ScriptForge.Basic service

The ScriptForge.Basic service proposes a collection of LibreOffice Basic methods to be executed in a Python context. Basic service methods reproduce the exact syntax and behaviour of Basic builtin functions.

Typical example:


   bas.MsgBox('Display this text in a message box from a Python script')
  
warning

ScriptForge.Basic service is limited to Python scripts.


Service invocation

note

Before using the Basic service, import the CreateScriptService() method from the scriptforge module:



    from scriptforge import CreateScriptService
    bas = CreateScriptService("Basic")
  

Properties

Name

ReadOnly

Type

Description

MB_OK, MB_OKCANCEL, MB_RETRYCANCEL, MB_YESNO, MB_YESNOCANCEL

Yes

Integer

Values: 0, 1, 5, 4, 3

MB_ICONEXCLAMATION, MB_ICONINFORMATION, MB_ICONQUESTION, MB_ICONSTOP

Yes

Integer

Values: 48, 64, 32, 16

MB_ABORTRETRYIGNORE, MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3

Yes

Integer

Values: 2, 128, 256, 512

IDABORT, IDCANCEL, IDIGNORE, IDNO, IDOK, IDRETRY, IDYES

Yes

Integer

Values: 3, 2, 5, 7, 1, 4, 6
Constants indicating MsgBox selected button.

StarDesktop

Yes

UNO
object

Returns the StarDesktop object that represents the LibreOffice application.

ThisComponent

Yes

UNO
object

If the current component refers to a LibreOffice document, this method returns the UNO object representing the document. This property returns None when the current component does not correspond to a document.

ThisDatabaseDocument

Yes

UNO
object

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 property returns None otherwise.


List of Methods in the Basic Service

CDate
CDateFromUnoDateTime
CDateToUnoDateTime
ConvertFromUrl
ConvertToUrl
CreateUnoService
CreateUnoStruct
DateAdd

DateDiff
DatePart
DateValue
Format
GetDefaultContext
GetGuiType
GetPathSeparator
GetSystemTicks

GlobalScope.BasicLibraries
GlobalScope.DialogLibraries
InputBox
MsgBox
Now
RGB
Xray


CDate

Converts a numeric expression or a string to a datetime.datetime Python native object.

note

This method exposes the Basic builtin function CDate to Python scripts.


Syntax:

svc.CDate(expression: any): obj

Parameters:

expression: a numeric expression or a string representing a date.

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 - Languages and Locales - General) 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:


    d = bas.CDate(1000.25)
    bas.MsgBox(str(d)) # 1902-09-26 06:00:00
    bas.MsgBox(d.year) # 1902
  

CDateFromUnoDateTime

Converts a UNO date/time representation to a datetime.datetime Python native object.

Syntax:

svc.CDateFromUnoDateTime(unodate: uno): obj

Parameters:

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

Example:

The following example creates a com.sun.star.util.DateTime object and converts it to a datetime.datetime Python object.


    uno_date = bas.CreateUnoStruct('com.sun.star.util.DateTime')
    uno_date.Year = 1983
    uno_date.Month = 2
    uno_date.Day = 23
    new_date = bas.CDateFromUnoDateTime(uno_date)
    bas.MsgBox(str(new_date)) # 1983-02-23 00:00:00
  

CDateToUnoDateTime

Converts a date representation into a com.sun.star.util.DateTime object.

Syntax:

svc.CDateToUnoDateTime(date: obj): uno

Parameters:

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.

Example:


    from datetime import datetime
    current_datetime = datetime.now()
    uno_date = bas.CDateToUnoDateTime(current_datetime)
    bas.MsgBox(str(uno_date.Year) + "-" + str(uno_date.Month) + "-" + str(uno_date.Day))
  

ConvertFromUrl

Returns a system path file name for the given file: URL.

Syntax:

svc.ConvertFromUrl(url: str): str

Parameters:

url: An absolute file: URL.

Return value:

A system path file name.

Example:


    filename = bas.ConvertFromUrl( "file:///C:/Program%20Files%20(x86)/LibreOffice/News.txt")
    bas.MsgBox(filename)
  

ConvertToUrl

Returns a file: URL for the given system path.

Syntax:

svc.ConvertToUrl(systempath: str): str

Parameters:

systempath: A system file name as a string.

Return value:

A file: URL as a string.

Example:


    url = bas.ConvertToUrl( 'C:\Program Files(x86)\LibreOffice\News.txt')
    bas.MsgBox(url)
  

CreateUnoService

Instantiates a UNO service with the ProcessServiceManager.

Syntax:

svc.CreateUnoService(servicename: str): uno

Parameters:

servicename: A fully qualified service name such as com.sun.star.ui.dialogs.FilePicker or com.sun.star.sheet.FunctionAccess.

Example:


    dsk = bas.CreateUnoService('com.sun.star.frame.Desktop')
  

CreateUnoStruct

Returns an instance of a UNO structure of the specified type.

Syntax:

svc.CreateUnoStruct(unostructure: str): uno

Parameters:

unostructure: A fully qualified structure name such as com.sun.star.beans.Property or com.sun.star.util.DateTime.

Example:


    date_struct = CreateUnoStruct('com.sun.star.util.DateTime')
  

DateAdd

Adds a date or time interval to a given date/time a number of times and returns the resulting date.

Syntax:

svc.DateAdd(interval: str, number: num, date: datetime): datetime

Parameters:

interval: A string expression from the following table, specifying the date or time interval.

interval (string value)

āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž

yyyy

āĻŦāĻ›āĻ°

q

āĻšāĻ¤ā§āĻ°ā§āĻĨāĻžāĻ‚āĻļ

m

āĻŽāĻžāĻ¸

y

āĻŦāĻ›āĻ°ā§‡āĻ° āĻĻāĻŋāĻ¨

w

āĻ•āĻ°ā§āĻŽāĻĻāĻŋāĻŦāĻ¸

ww

āĻŦāĻ›āĻ°ā§‡āĻ° āĻ¸āĻĒā§āĻ¤āĻžāĻš

d

āĻĻāĻŋāĻ¨

h

āĻ˜āĻ¨ā§āĻŸāĻž

n

āĻŽāĻŋāĻ¨āĻŋāĻŸ

s

āĻ¸ā§‡āĻ•ā§‡āĻ¨ā§āĻĄ


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 datetime.datetime value.

Return value:

A datetime.datetime value.

Example:


    dt = datetime.datetime(2004, 1, 31)
    dt = bas.DateAdd("m", 1, dt)
    print(dt)
  

DateDiff

Returns the number of date or time intervals between two given date/time values.

Syntax:

svc.DateDiff(interval: str, date1: datetime, date2: datetime, firstdayofweek = 1, firstweekofyear = 1): int

Parameters:

interval: A string expression specifying the date interval, as detailed in above DateAdd method.

date1, date2: The two datetime.datetime values to be compared.

firstdayofweek: An optional parameter that specifies the starting day of a week.

firstdayofweek value

āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž

0

āĻ¸āĻŋāĻ¸ā§āĻŸā§‡āĻŽā§‡āĻ° āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ āĻŽāĻžāĻ¨ āĻŦā§āĻ¯āĻŦāĻšā§ƒāĻ¤ āĻšā§Ÿ

1

āĻ°āĻŦāĻŋāĻŦāĻžāĻ° (āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ)

2

āĻ¸ā§‹āĻŽāĻŦāĻžāĻ°

3

āĻŽāĻ™ā§āĻ—āĻ˛āĻŦāĻžāĻ°

4

āĻŦā§āĻ§āĻŦāĻžāĻ°

5

āĻŦā§ƒāĻšāĻ¸ā§āĻĒāĻ¤āĻŋāĻŦāĻžāĻ°

6

āĻļā§āĻ•ā§āĻ°āĻŦāĻžāĻ°

7

āĻļāĻ¨āĻŋāĻŦāĻžāĻ°


firstweekofyear: An optional parameter that specifies the starting week of a year.

firstweekofyear value

āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž

0

āĻ¸āĻŋāĻ¸ā§āĻŸā§‡āĻŽā§‡āĻ° āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ āĻŽāĻžāĻ¨ āĻŦā§āĻ¯āĻŦāĻšā§ƒāĻ¤ āĻšā§Ÿ

1

āĻŦāĻ›āĻ°ā§‡āĻ° ā§§āĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻšāĻŸāĻŋ āĻšāĻ˛ā§‹ ā§§āĻ˛āĻž āĻœāĻžāĻ¨ā§ā§ŸāĻžāĻ°āĻŋ āĻ¸āĻŽā§āĻŦāĻ˛āĻŋāĻ¤ āĻ¸āĻĒā§āĻ¤āĻžāĻš (āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ)

2

āĻ¸āĻĒā§āĻ¤āĻžāĻš ā§§ āĻšāĻ˛ā§‹ āĻ¸ā§‡āĻ‡ āĻŦāĻ›āĻ°ā§‡āĻ° āĻšāĻžāĻ° āĻ…āĻĨāĻŦāĻž āĻ¤āĻ¤ā§‹āĻ§āĻŋāĻ• āĻĻāĻŋāĻ¨ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻŸ āĻĒā§āĻ°āĻĨāĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻš

3

āĻ¸āĻĒā§āĻ¤āĻžāĻš ā§§ āĻšāĻ˛ā§‹ āĻ¨āĻ¤ā§āĻ¨ āĻŦāĻ›āĻ°ā§‡āĻ° āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻĻāĻŋāĻ¨ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻŸ āĻĒā§āĻ°āĻĨāĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻš


Return value:

A number.

Example:


    date1 = datetime.datetime(2005,1, 1)
    date2 = datetime.datetime(2005,12,31)
    diffDays = bas.DateDiff('d', date1, date2)
    print(diffDays)
  

DatePart

The DatePart function returns a specified part of a date.

Syntax:

svc.DatePart(interval: str, date: datetime, firstdayofweek = 1, firstweekofyear = 1): int

Parameters:

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.

Return value:

The extracted part for the given date/time.

Example:


    print(bas.DatePart("ww", datetime.datetime(2005,12,31)
    print(bas.DatePart('q', datetime.datetime(1999,12,30)
  

DateValue

Computes a date value from a date string.

Syntax:

svc.DateValue(date: str): datetime

Parameters:

date: A string that contains the date that will be converted to a Date object.

note

The string passed to DateValue must be expressed in one of the date formats defined by your locale setting (see - Languages and Locales - General) or using the ISO date format "yyyy-mm-dd" (year, month and day separated by hyphens).


Return value:

The computed date.

Example:


    dt = bas.DateValue("23-02-2011")
    print(dt)
  

Format

Converts a number to a string, and then formats it according to the format that you specify.

Syntax:

svc.Format(expression: any, format = ''): str

Parameters:

expression: Numeric expression that you want to convert to a formatted string.

format: String that specifies the format code for the number. If format is omitted, the Format function works like the LibreOffice Basic Str() function.

Return value:

Text string.

Formatting Codes

The following list describes the codes that you can use for formatting a numeric expression:

0: If expression has a digit at the position of the 0 in the format code, the digit is displayed, otherwise a zero is displayed.

If expression has fewer digits than the number of zeros in the format code, (on either side of the decimal), leading or trailing zeros are displayed. If the expression has more digits to the left of the decimal separator than the amount of zeros in the format code, the additional digits are displayed without formatting.

Decimal places in the expression are rounded according to the number of zeros that appear after the decimal separator in the format code.

#: If expression contains a digit at the position of the # placeholder in the format code, the digit is displayed, otherwise nothing is displayed at this position.

This symbol works like the 0, except that leading or trailing zeroes are not displayed if there are more # characters in the format code than digits in the expression. Only the relevant digits of the expression are displayed.

.: āĻĻāĻļāĻŽāĻŋāĻ• āĻ¸ā§āĻĨāĻžāĻ¨āĻ§āĻžāĻ°āĻ•āĻŸāĻŋ āĻĻāĻļāĻŽāĻŋāĻ• āĻŦāĻŋāĻ­āĻžāĻœāĻ•ā§‡āĻ° āĻŦāĻžāĻŽ āĻ…āĻĨāĻŦāĻž āĻĄāĻžāĻ¨ā§‡āĻ° āĻĻāĻļāĻŽāĻŋāĻ• āĻ¸ā§āĻĨāĻžāĻ¨ āĻ¨āĻŋāĻ°ā§āĻ§āĻžāĻ°āĻŖ āĻ•āĻ°ā§‡ āĻĨāĻžāĻ•ā§‡āĨ¤

If the format code contains only # placeholders to the left of this symbol, numbers less than 1 begin with a decimal separator. To always display a leading zero with fractional numbers, use 0 as a placeholder for the first digit to the left of the decimal separator.

%: Multiplies the expressionby 100 and inserts the percent sign (%) where the expression appears in the format code.

E- E+ e- e+ : If the format code contains at least one digit placeholder (0 or #) to the right of the symbol E-, E+, e-, or e+, the expression is formatted in the scientific or exponential format. The letter E or e is inserted between the number and the exponent. The number of placeholders for digits to the right of the symbol determines the number of digits in the exponent.

āĻ¯āĻĻāĻŋ āĻāĻ•āĻŸāĻŋ āĻ¸ā§‚āĻšāĻ• āĻ‹āĻ¨āĻžāĻ¤ā§āĻŦāĻ• āĻšā§Ÿ āĻ¤āĻžāĻšāĻ˛ā§‡ E-, E+, e-, e+ āĻ¸āĻš āĻāĻ•āĻŸāĻŋ āĻ¸ā§‚āĻšāĻ•ā§‡āĻ° āĻĒāĻŋāĻ›āĻ¨ā§‡ āĻ¸āĻ°āĻžāĻ¸āĻ°āĻŋ āĻāĻ•āĻŸāĻŋ āĻŦāĻŋā§Ÿā§‹āĻ— āĻšāĻŋāĻšā§āĻ¨ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšā§ŸāĨ¤ āĻ¯āĻĻāĻŋ āĻ¸ā§‚āĻšāĻ•āĻŸāĻŋ āĻ§ā§āĻŦāĻ¨āĻžāĻ¤ā§āĻŦāĻ• āĻšā§Ÿ āĻ¤āĻžāĻšāĻ˛ā§‡ E+ āĻ…āĻĨāĻŦāĻž e+ āĻ¸āĻš āĻ¸ā§‚āĻšāĻ•ā§‡āĻ° āĻĒāĻŋāĻ›āĻ¨ā§‡ āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻāĻ•āĻŸāĻŋ āĻ¯ā§‹āĻ— āĻšāĻŋāĻšā§āĻ¨ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšā§ŸāĨ¤

The thousands delimiter is displayed if the format code contains the delimiter enclosed by digit placeholders (0 or #).

āĻ¸āĻšāĻ¸ā§āĻ° āĻāĻŦāĻ‚ āĻĻāĻļāĻŽāĻŋāĻ• āĻŦāĻŋāĻ­āĻžāĻœāĻ• āĻšāĻŋāĻ¸ā§‡āĻŦā§‡ āĻĒāĻ°ā§āĻ¯āĻžāĻ¯āĻŧāĻ•āĻžāĻ˛ā§‡āĻ° āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻāĻ˛āĻžāĻ•āĻž āĻ­āĻŋāĻ¤ā§āĻ¤āĻŋāĻ• āĻ¸ā§‡āĻŸāĻŋāĻ‚ āĻāĻ° āĻ‰āĻĒāĻ° āĻ¨āĻŋāĻ°ā§āĻ­āĻ°āĻļā§€āĻ˛āĨ¤ āĻ¯āĻ–āĻ¨ āĻ†āĻĒāĻ¨āĻŋ āĻŽā§‚āĻ˛ āĻ¸ā§‹āĻ°ā§āĻ¸ āĻ•ā§‹āĻĄā§‡ āĻ¸āĻ°āĻžāĻ¸āĻ°āĻŋ āĻāĻ•āĻŸāĻŋ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻ¸āĻ¨ā§āĻ¨āĻŋāĻŦā§‡āĻļ āĻ•āĻ°āĻžāĻ¨ā§‹āĻ° āĻ¸āĻŽā§Ÿ, āĻ¸āĻŦāĻ¸āĻŽāĻ¯āĻŧ āĻĻāĻļāĻŽāĻŋāĻ• āĻŦāĻŋāĻ­ā§‡āĻĻāĻ• āĻšāĻŋāĻ¸ā§‡āĻŦā§‡ āĻāĻ•āĻŸāĻŋ āĻĒāĻ°ā§āĻ¯āĻžāĻ¯āĻŧāĻ•āĻžāĻ˛ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°ā§āĻ¨āĨ¤ āĻĻāĻļāĻŽāĻŋāĻ• āĻŦāĻŋāĻ­āĻžāĻœāĻ• āĻšāĻŋāĻ¸ā§‡āĻŦā§‡ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻĒā§āĻ°āĻ•ā§ƒāĻ¤ āĻ…āĻ•ā§āĻˇāĻ°āĻŸāĻŋ āĻ†āĻĒāĻ¨āĻžāĻ° āĻ¸āĻŋāĻ¸ā§āĻŸā§‡āĻŽ āĻ¸ā§‡āĻŸāĻŋāĻ‚ āĻ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻžāĻ° āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ā§‡āĻ° āĻ‰āĻĒāĻ° āĻ¨āĻŋāĻ°ā§āĻ­āĻ°āĻļā§€āĻ˛āĨ¤

- + $ ( ) space: A plus (+), minus (-), dollar ($), space, or brackets entered directly in the format code is displayed as a literal character.

āĻāĻ–āĻžāĻ¨ā§‡ āĻ¤āĻžāĻ˛āĻŋāĻ•āĻžāĻŦāĻĻā§āĻ§ āĻ¨ā§Ÿ āĻāĻŽāĻ¨ āĻ…āĻ•ā§āĻˇāĻ° āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻ¨ā§‡āĻ° āĻœāĻ¨ā§āĻ¯, āĻāĻŸāĻŋāĻ° āĻ…āĻŦāĻļā§āĻ¯āĻ‡ āĻāĻ•āĻŸāĻŋ āĻĒā§‚āĻ°ā§āĻŦāĻŦāĻ°ā§āĻ¤ā§€ āĻŦā§āĻ¯āĻžāĻ•āĻļā§āĻ˛ā§āĻ¯āĻžāĻļ (‌\\) āĻĨāĻžāĻ•āĻ¤ā§‡ āĻšāĻŦā§‡ āĻ…āĻĨāĻŦāĻž āĻāĻ•āĻŸāĻŋ āĻ‰āĻĻā§āĻ§ā§ƒāĻ¤āĻŋ āĻšāĻŋāĻšā§āĻ¨ (" ") āĻĻā§āĻŦāĻžāĻ°āĻž āĻ†āĻŦāĻĻā§āĻ§ āĻĨāĻžāĻ•āĻ¤ā§‡ āĻšāĻŦā§‡āĨ¤

\ : The backslash displays the next character in the format code.

Characters in the format code that have a special meaning can only be displayed as literal characters if they are preceded by a backslash. The backslash itself is not displayed, unless you enter a double backslash (\\) in the format code.

āĻ†āĻ•ā§āĻˇāĻ°āĻŋāĻ• āĻšāĻŋāĻ¸ā§‡āĻŦā§‡ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻ¨ā§‡āĻ° āĻœāĻ¨ā§āĻ¯ āĻ…āĻ•ā§āĻˇāĻ°ā§‡āĻ° āĻĒā§‚āĻ°ā§āĻŦā§‡ āĻ…āĻŦāĻļā§āĻ¯āĻ‡ āĻāĻ•āĻŸāĻŋ āĻŦā§āĻ¯āĻžāĻ•āĻ¸ā§āĻ˛ā§āĻ¯āĻžāĻļ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻŸ āĻ…āĻ•ā§āĻˇāĻ° āĻšāĻ˛ā§‹ āĻ¤āĻžāĻ°āĻŋāĻ– āĻāĻŦāĻ‚ āĻ¸āĻŽā§Ÿ āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ (a, c, d, h, m, n, p, q, s, t, w, y, /, :), āĻ¸āĻ‚āĻ–ā§āĻ¯āĻžāĻ¸ā§‚āĻšāĻ•-āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ āĻ…āĻ•ā§āĻˇāĻ° (#, 0, %, E, e, comma, period), āĻāĻŦāĻ‚ āĻˇā§āĻŸā§āĻ°āĻŋāĻ‚-āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ āĻ…āĻ•ā§āĻˇāĻ° (@, &, <, >, !)āĨ¤

You can also use the following predefined number formats. Except for "General Number", all of the predefined format codes return the number as a decimal number with two decimal places.

āĻ†āĻĒāĻ¨āĻŋ āĻ¯āĻĻāĻŋ āĻĒā§‚āĻ°ā§āĻŦāĻ¨āĻŋāĻ°ā§āĻ§āĻžāĻ°āĻŋāĻ¤ āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°ā§‡āĻ¨ āĻ¤āĻžāĻšāĻ˛ā§‡, āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ā§‡āĻ° āĻ¨āĻžāĻŽāĻŸāĻŋ āĻ…āĻŦāĻļā§āĻ¯āĻ‡ āĻ‰āĻĻā§āĻ§ā§ƒāĻ¤āĻŋ-āĻšāĻŋāĻšā§āĻ¨ā§‡āĻ° āĻŽāĻ§ā§āĻ¯ā§‡ āĻ°āĻžāĻ–āĻ¤ā§‡ āĻšāĻŦā§‡āĨ¤

Predefined Formats

āĻ¸āĻžāĻ§āĻžāĻ°āĻŖ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž: āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻĒā§āĻ°āĻŦā§‡āĻļā§‡āĻ° āĻ•ā§āĻ°āĻŽ āĻ…āĻ¨ā§āĻ¸āĻžāĻ°ā§‡ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšā§ŸāĨ¤

āĻŽā§‚āĻĻā§āĻ°āĻž: āĻ¸āĻ‚āĻ–ā§āĻ¯āĻžāĻ° āĻ¸āĻžāĻŽāĻ¨ā§‡ āĻāĻ•āĻŸāĻŋ āĻĄāĻ˛āĻžāĻ° āĻšāĻŋāĻšā§āĻ¨ ($) āĻ¸āĻ¨ā§āĻ¨āĻŋāĻŦā§‡āĻļ āĻ•āĻ°āĻžāĻ¨ā§‹ āĻšā§Ÿ āĻāĻŦāĻ‚ āĻ‹āĻ¨āĻžāĻ¤ā§āĻŦāĻ• āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻŦāĻ¨ā§āĻ§āĻ¨ā§€ āĻĻā§āĻŦāĻžāĻ°āĻž āĻ†āĻŦāĻĻā§āĻ§ āĻ•āĻ°āĻž āĻšā§ŸāĨ¤

āĻ¨āĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āĻŸ: āĻĻāĻļāĻŽāĻŋāĻ• āĻŦāĻŋāĻ­āĻžāĻœāĻ•ā§‡āĻ° āĻ¸āĻžāĻŽāĻ¨ā§‡ āĻ…āĻ¨ā§āĻ¤āĻ¤ āĻāĻ• āĻĄāĻŋāĻœāĻŋāĻŸ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšāĻŦā§‡āĨ¤

āĻ†āĻĻāĻ°ā§āĻļ: āĻāĻ•āĻŸāĻŋ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻšāĻžāĻœāĻžāĻ° āĻŦāĻŋāĻ­āĻžāĻœāĻ• āĻ¸āĻš āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšā§ŸāĨ¤

āĻļāĻ¤āĻ•āĻ°āĻž: āĻ¸āĻ‚āĻ–ā§āĻ¯āĻžāĻŸāĻŋāĻ•ā§‡ ā§§ā§Ļā§Ļ āĻĻā§āĻŦāĻžāĻ°āĻž āĻ—ā§āĻŖ āĻ•āĻ°āĻž āĻšā§Ÿ āĻāĻŦāĻ‚ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻžāĻ° āĻļā§‡āĻˇā§‡ āĻāĻ•āĻŸāĻŋ āĻļāĻ¤āĻ•āĻ°āĻž āĻšāĻŋāĻšā§āĻ¨ āĻ¯ā§‹āĻ— āĻ•āĻ°āĻž āĻšā§ŸāĨ¤

āĻŦā§ˆāĻœā§āĻžāĻžāĻ¨āĻŋāĻ•: āĻŦā§ˆāĻœā§āĻžāĻžāĻ¨āĻŋāĻ• āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ā§‡ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻŋāĻ¤ āĻšā§Ÿ (āĻ¯ā§‡āĻŽāĻ¨, 1000 āĻāĻ° āĻœāĻ¨ā§āĻ¯ 1.00E+03 )āĨ¤

A format code can be divided into three sections that are separated by semicolons. The first part defines the format for positive values, the second part for negative values, and the third part for zero. If you only specify one format code, it applies to all numbers.

You can set the locale used for controlling the formatting numbers, dates and currencies in LibreOffice Basic in - Languages and Locales - General. In Basic format codes, the decimal point (.) is always used as placeholder for the decimal separator defined in your locale and will be replaced by the corresponding character.

āĻ¤āĻžāĻ°āĻŋāĻ–, āĻ¸āĻŽāĻ¯āĻŧ āĻāĻŦāĻ‚ āĻŽā§āĻĻā§āĻ°āĻžāĻ° āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ā§‡āĻ° āĻœāĻ¨ā§āĻ¯ āĻ¸ā§āĻĨāĻžāĻ¨ā§€ā§Ÿ āĻ¸ā§‡āĻŸāĻŋāĻ‚ āĻ āĻāĻ•āĻ‡ āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ āĻĒā§āĻ°āĻ¯āĻŧā§‹āĻ— āĻ•āĻ°āĻž āĻšāĻ¯āĻŧāĨ¤ āĻāĻ‡ āĻŽā§‚āĻ˛ āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ āĻ•ā§‹āĻĄāĻŸāĻŋ āĻ†āĻĒāĻ¨āĻžāĻ° āĻ¸ā§āĻĨāĻžāĻ¨ā§€āĻ¯āĻŧ āĻ¸ā§‡āĻŸāĻŋāĻ‚ āĻ…āĻ¨ā§āĻ¯āĻžāĻ¯āĻŧā§€ āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž āĻ•āĻ°āĻž āĻāĻŦāĻ‚ āĻĒā§āĻ°āĻĻāĻ°ā§āĻļāĻ¨ āĻ•āĻ°āĻž āĻšāĻŦā§‡āĨ¤

Example:


    txt = bas.Format(6328.2, '##.##0.00')
    print(txt)
  

GetDefaultContext

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.

Syntax:

svc.GetDefaultContext(): uno

Return value:

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.

Example:


    ctx = bas.GetDefaultContext()
  

GetGuiType

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.

Syntax:

svc.GetGuiType(): int

Example:


    n = bas.GetGuiType()
  

GetPathSeparator

Returns the operating system-dependent directory separator used to specify file paths.

Use os.pathsep from os Python module to identify the path separator.

Syntax:

svc.GetPathSeparator(): str

Example:


    sep = bas.GetPathSeparator()
  

GetSystemTicks

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:

Syntax:

svc.GetSystemTicks(): int

Example:


    ticks_ini = bas.GetSystemTicks()
    time.sleep(1)
    ticks_end = bas.GetSystemTicks()
    bas.MsgBox("{} - {} = {}".format(ticks_end, ticks_ini,ticks_end - ticks_ini))
  

GlobalScope.BasicLibraries

Returns the UNO object containing all shared Basic libraries and modules.

This method is the Python equivalent to GlobalScope.BasicLibraries in Basic scripts.

Syntax:

svc.GlobalScope.BasicLibraries(): uno

Return value:

com.sun.star.script.XLibraryContainer

Example:

The following example loads the Gimmicks Basic library if it has not been loaded yet.


    libs = bas.GlobalScope.BasicLibraries()
    if not libs.isLibraryLoaded("Gimmicks"):
        libs.loadLibrary("Gimmicks")
  

GlobalScope.DialogLibraries

Returns the UNO object containing all shared dialog libraries.

This method is the Python equivalent to GlobalScope.DialogLibraries in Basic scripts.

Syntax:

svc.GlobalScope.DialogLibraries(): uno

Return value:

com.sun.star.comp.sfx2.DialogLibraryContainer

Example:

The following example shows a message box with the names of all available dialog libraries.


    dlg_libs = bas.GlobalScope.DialogLibraries()
    lib_names = dlg_libs.getElementNames()
    bas.MsgBox("\n".join(lib_names))
  

InputBox

Syntax:

svc.InputBox(prompt: str, [title: str], [default: str], [xpostwips: int, ypostwips: int]): str

Parameters:

prompt: String expression displayed as the message in the dialog box.

title: String expression displayed in the title bar of the dialog box.

default: String expression displayed in the text box as default if no other input is given.

xpostwips: Integer expression that specifies the horizontal position of the dialog. The position is an absolute coordinate and does not refer to the window of LibreOffice.

ypostwips: Integer expression that specifies the vertical position of the dialog. The position is an absolute coordinate and does not refer to the window of LibreOffice.

If xpostwips and ypostwips are omitted, the dialog is centered on the screen. The position is specified in twips.

Return value:

String

Example:


    txt = s.InputBox('Please enter a phrase:', "Dear user")
    s.MsgBox(txt, s.MB_ICONINFORMATION, "Confirmation of phrase")
  
note

For in-depth information please refer to Input/Output to Screen with Python on the Wiki.


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.

Syntax:

bas.MsgBox(prompt: str, [buttons: int], [title: str])[: int]

Parameters:

prompt: String expression displayed as a message in the dialog box. Line breaks can be inserted with Chr$(13).

title: String expression displayed in the title bar of the dialog. If omitted, the title bar displays the name of the respective application.

buttons: Any integer expression that specifies the dialog type, as well as the number and type of buttons to display, and the icon type. buttons represents a combination of bit patterns, that is, a combination of elements can be defined by adding their respective values:

Return value:

An optional integer as detailed in above IDxx properties.

Example:


    txt = s.InputBox('Please enter a phrase:', "Dear user")
    s.MsgBox(txt, s.MB_ICONINFORMATION, "Confirmation of phrase")
  
note

For in-depth information please refer to Input/Output to Screen with Python on the Wiki.


Now

Returns the current system date and time as a datetime.datetime Python native object.

Syntax:

svc.Now(): datetime

Example:


    bas.MsgBox(bas.Now(), bas.MB_OK, "Now")
  

RGB

Returns an integer color value consisting of red, green, and blue components.

Syntax:

svc.RGB(red:int, green: int, blue: int): int

Parameters:

red: Any integer expression that represents the red component (0-255) of the composite color.

green: Any integer expression that represents the green component (0-255) of the composite color.

blue: Any integer expression that represents the blue component (0-255) of the composite color.

The resulting Long value is calculated with the following formula:
Result = red×65536 + green×256 + blue.

warning

Under VBA compatibility mode (Option VBASupport 1), the Long value is calculated as
Result = red + green×256 + blue×65536
See RGB Function [VBA]


tip

The color picker dialog helps computing red, green and blue components of a composite color. Changing the color of text and selecting Custom color displays the color picker dialog.


Return value:

Integer

Example:


    YELLOW = bas.RGB(255,255,0)
  

Xray

Inspect Uno objects or variables.

Syntax:

svc.Xray(obj: any)

Parameters:

obj: A variable or UNO object.

Example:


    bas.Xray(bas.StarDesktop)
  
warning

All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.


Please support us!