+ Converts a numeric expression or a string to a datetime.datetime Python native object.
+ This method exposes the Basic builtin function CDate to Python scripts.
+
+
+ svc.CDate(expression: any): obj
+
+
+ expression: a numeric expression or a string representing a date.
+
+
+
+ d = svc.CDate(1000.25)
+ svc.MsgBox(str(d)) # 1902-09-26 06:00:00
+ svc.MsgBox(d.year) # 1902
+
+
+
+
+ CDateFromUnoDateTime -------------------------------------------------------------------------
+
+ Basic service;CDateFromUnoDateTime
+
+
CDateFromUnoDateTime
+ Converts a UNO date/time representation to a datetime.datetime Python native object.
+
+
+ svc.CDateFromUnoDateTime(unodate: uno): obj
+
+
+ unodate: A UNO date/time object of one of the following types: com.sun.star.util.DateTime, com.sun.star.util.Date or com.sun.star.util.Time
+
+ The following example creates a com.sun.star.util.DateTime object and converts it to a datetime.datetime Python object.
+
+ import uno
+ uno_date = uno.createUnoStruct('com.sun.star.util.DateTime')
+ uno_date.Year = 1983
+ uno_date.Month = 2
+ uno_date.Day = 23
+ new_date = svc.CDateFromUnoDateTime(uno_date)
+ svc.MsgBox(str(new_date)) # 1983-02-23 00:00:00
+
+
+
+
+ CDateToUnoDateTime -------------------------------------------------------------------------
+
+ Basic service;CDateToUnoDateTime
+
+
CDateToUnoDateTime
+ Converts a date representation into a com.sun.star.util.DateTime object.
+
+
+ svc.CDateToUnoDateTime(date: obj): uno
+
+
+ date: A Python date/time object of one of the following types: datetime.datetime, datetime.date, datetime.time, float (time.time) or time.struct_time.
+
+
+ from datetime import datetime
+ current_datetime = datetime.now()
+ uno_date = svc.CDateToUnoDateTime(current_datetime)
+ svc.MsgBox(str(uno_date.Year) + "-" + str(uno_date.Month) + "-" + str(uno_date.Day))
+
+
+
ConvertFromUrl -------------------------------------------------------------------------
@@ -159,18 +238,19 @@
ConvertFromUrl
Returns a system path file name for the given file: URL.
-
+
interval: A string expression from the following table, specifying the date or time interval.number: A numerical expression specifying how often the interval value will be added when positive or subtracted when negative.date: A given datetime.datetime value, the interval value will be added number times to this date/time value.
-
+
interval: A string expression specifying the date interval, as detailed in above DateAdd method.date1, date2: The two datetime.datetime values to be compared.
-
+
interval: A string expression specifying the date interval, as detailed in above DateAdd method.date: The date/time from which the result is calculated.firstdayofweek, firstweekofyear: optional parameters that respectively specify the starting day of a week and the starting week of a year, as detailed in above DateDiff method.
-
Returns the default context of the process service factory, if existent, else returns a null reference.GetDefaultContext is an alternative to the getComponentContext() method available from XSCRIPTCONTEXT global variable or from uno.py module.
-
+
svc.GetDefaultContext(): uno
-
+
The default component context is used, when instantiating services via XMultiServiceFactory. See the Professional UNO chapter in the Developer's Guide on api.libreoffice.org for more information.
-
Returns a numerical value that specifies the graphical user interface. This function is only provided for backward compatibility with previous versions.Refer to system() method from platform Python module to identify the operating system.
-
Returns the operating system-dependent directory separator used to specify file paths.Use os.pathsep from os Python module to identify the path separator.
-
Returns the number of system ticks provided by the operating system. You can use this function to optimize certain processes. Use this method to estimate time in milliseconds:
-
+ Returns the UNO object containing all shared Basic libraries and modules.
+ This method is the Python equivalent to GlobalScope.BasicLibraries in Basic scripts.
+
+
+ svc.GlobalScope.BasicLibraries(): uno
+
+
+ com.sun.star.script.XLibraryContainer
+
+ The following example loads the Gimmicks Basic library if it has not been loaded yet.
+
+ libs = svc.GlobalScope.BasicLibraries()
+ if not libs.isLibraryLoaded("Gimmicks"):
+ libs.loadLibrary("Gimmicks")
+
+
+
+
+ InputBox -------------------------------------------------------------------------------
+
+ Basic service;GlobalScope.DialogLibraries
+
+
GlobalScope.DialogLibraries
+ Returns the UNO object containing all shared dialog libraries.
+ This method is the Python equivalent to GlobalScope.DialogLibraries in Basic scripts.
+
+
+ svc.GlobalScope.DialogLibraries(): uno
+
+
+ com.sun.star.comp.sfx2.DialogLibraryContainer
+
+ The following example shows a message box with the names of all available dialog libraries.
+
+ dlg_libs = svc.GlobalScope.DialogLibraries()
+ lib_names = dlg_libs.getElementNames()
+ svc.MsgBox("\n".join(lib_names))
+
+
+
InputBox ------------------------------------------------------------------------------- Basic service;InputBox
-
+
txt = s.InputBox('Please enter a phrase:', "Dear user")
@@ -401,6 +538,7 @@
For in-depth information please refer to Input/Output to Screen with Python on the Wiki.
+
MsgBox --------------------------------------------------------------------------------
@@ -408,29 +546,31 @@
MsgBox
Displays a dialog box containing a message and returns an optional value. MB_xx constants help specify the dialog type, the number and type of buttons to display, plus the icon type. By adding their respective values they form bit patterns, that define the MsgBox dialog appearance.
-
+ If the current component refers to a %PRODUCTNAME document, this method returns the UNO object representing the document.
+ The method will return None when the current component does not correspond to a document.
+
+
+ svc.ThisComponent(): uno
+
+
+
+ comp = svc.ThisComponent
+ svc.MsgBox("\n".join(comp.getSupportedServiceNames()))
+
+
+
+
+ ThisDatabaseDocument ------------------------------------------
+
+ Basic service;ThisDatabaseDocument
+
+
ThisDatabaseDocument
+ If the script is being executed from a Base document or any of its subcomponents this method returns the main component of the Base instance.
+ This method returns None otherwise.
+
+
+ svc.ThisDatabaseDocument(): uno
+
+
+
+ db_doc = svc.ThisDatabaseDocument
+ table_names = db_doc.DataSource.getTables().getElementNames()
+ bas.MsgBox("\n".join(table_names))
+
+ Visit the OfficeDatabaseDocument API page to learn more about Base's main component structure.
+
+
- Xray -----------------------------------------------------------------------------------
+ Xray ------------------------------------------------------------ Basic service;Xray
Xray
Inspect Uno objects or variables.
-
+
svc.Xray(obj: any)
-
+
obj: A variable or Uno object.
-
+
- svc.Xray(svc.StarDesktop)
+ svc.Xray(svc.StarDesktop)
+
- uno.fileUrlToSystemPath() method
- uno.systemPathToFileUrl() method
+
+
+ uno.fileUrlToSystemPath()
+ uno.systemPathToFileUrl()Input/Output to Screen with Python on the wiki
- XSCRIPTCONTEXT.getComponentContext() method
- uno.getComponentContext() method
- platform.system() method
- os.pathsep() method
-
+ XSCRIPTCONTEXT.getComponentContext()
+ uno.getComponentContext()
+ platform.system()
+ os.pathsep()
+
-
CDate function
-
-
CDate FunctionConverts any string or numeric expression to a date value.
-Syntax:
+
CDate (Expression)
@@ -46,19 +43,20 @@
Return value:Date
-Parameters:
+
Expression: Any string or numeric expression that you want to convert.
-When you convert a string expression, the date and time must be entered either in one of the date acceptance patterns defined for your locale setting (see ) or in ISO date format (momentarily, only the ISO format with hyphens, e.g. "2012-12-31" is accepted). In numeric expressions, values to the left of the decimal represent the date, beginning from December 31, 1899. Values to the right of the decimal represent the time.
+
+ When you convert a string expression, the date and time must be entered either in one of the date acceptance patterns defined for your locale setting (see ) or in ISO date format (momentarily, only the ISO format with hyphens, e.g. "2012-12-31" is accepted). In numeric expressions, values to the left of the decimal represent the date, beginning from December 31, 1899. Values to the right of the decimal represent the time.
+
-
-Example:
+
-Sub ExampleCDate
- MsgBox cDate(1000.25) ' 09.26.1902 06:00:00
- MsgBox cDate(1001.26) ' 09.27.1902 06:14:24
-End Sub
+ Sub ExampleCDate
+ MsgBox cDate(1000.25) ' 09.26.1902 06:00:00
+ MsgBox cDate(1001.26) ' 09.27.1902 06:14:24
+ End Sub
-