Categories
gimlet fremantle menu

libreoffice basic programming guide pdf

The modules are of no other functional importance for LibreOffice Basic programmers. The origin of the objects is explained at a later point in this guide. The same interface provides methods moveByName and copyByName. The Format function formats numbers as a string. The example first checks if the error number corresponds to the expected number (as stored in the imaginary ExpectedErrorNo constant) and then handles the error accordingly. Basic can handle both methods like a property Name. Comparison operators can be applied to all elementary variable types (numbers, date details, strings, and Boolean values). Function calls, mathematical expressions, and other linguistic elements, such as function and loop headers, must be completed on the same line that they begin on. LibreOffice Basic provides an extensive interface for program-controlled creation and editing of spreadsheets. Both the X and Y-axes have a gray grid for visual orientation. LibreOffice Basic is a fully-developed procedural programming language and no longer requires rudimentary control structures, such as GoTo and GoSub. value in the left-hand text field of the header from the "Default" template. Direct formatting always takes priority over indirect formatting. You can open a dialog with the following code: CreateUnoDialog creates an object called Dlg that references the associated dialog. All of the drawing objects that are described in the previous sections can also be rotated and sheared using the com.sun.star.drawing.RotationDescriptor service. In LibreOffice, these properties are defined using a page style which in turn is linked to the associated document. A spreadsheet document provides properties and methods for formatting cells and pages. VBA: In VBA, the MkDir and RmDir functions only relate to the current directory. Strictly speaking, a PolyPolygon is not a simple polygon but a multiple polygon. Properties are like the properties of an object; for example, Filename and Title for a Document object. Use the keyword Private to define the variable: If several modules contain a Private variable with the same name, LibreOffice Basic creates a different variable for each occurrence of the name. To convert local file names into a URL, LibreOffice provides the ConvertToUrl function. LibreOffice Basic provides the MsgBox and InputBox functions for basic user communication. Common pieces of reusable Python or UNO features must be stored in My macros within (User Profile)/Scripts/python/pythonpath. If you use the CompatibilityMode ( true ) function, LibreOffice Basic will behave like VBA. Some DOS-specific file and directory functions are no longer provided in LibreOffice, or their function is only limited. These include tables, drawings, text fields and directories. The loadComponentFromURL function introduced in the previous section returns a document object. A variant is a universal variable that can record all conceivable values, including strings, whole numbers, floating point figures, and Boolean values. For example, this object provides a start method that can start presentations. This function is similar to the one that is used in text documents as described in #Text Documents. You can use these properties to trigger an event within an event handler. For example, you can check whether a user has typed a valid number or date. All properties form part of the associated model objects. When working with the indexes, note that getCount returns the number of elements. While this term may be familiar to Java programmers, it is not used in Basic. The following properties of an option button are available through its model object: The mechanism for grouping option buttons distinguishes between the control elements for dialogs and forms. You must use whole numbers that are preceded by &O. Boolean variables can only contain one of two values: True or False. The options for accessing text tables are described in the following section. In this guide, a table-based document or spreadsheet document is the entire document, whereas a spreadsheet (or sheet for short) is a sheet (table) in the document. Warning: The figure above shows the LibreOffice Basic development environment with a dialog window that contains two list boxes. If you understand the last example, then you also know why this example does not do what it appears. The active document object is accessed in LibreOffice through the StarDesktop.CurrentComponent property, or through ThisComponent. LibreOffice then changes the way in which all text portions which use this template are depicted. The only way to have a fixed page name is to rename the page, by the user interface or by programming. It converts a string into a number; however it always expects a period to be used as the decimal point symbol. The Diagram object provides the following properties to access the axes: The axis objects of a LibreOffice chart support the com.sun.star.chart.ChartAxis service. Basic Programming Examples Creating a Dialog Handler Creating Event Listeners Getting Session Information Identifying the operating system Monitoring Document Events Opening a Dialog With Basic Programming Examples for Controls in the Dialog Editor Calling Python Scripts from Basic Related Topics LibreOffice Basic Help Please support us! A Const definition in the module header is available to the code in that module. For more information, see the LibreOffice API reference. Once the writing process has been completed, the file must be closed using a Close call: Again here, the file handle should be specified. There are, however, a few key differences: Users who want to provide their forms with their own methods for event handling, should refer to the #Dialogs chapter. The 0 (zero) used as the second parameter in the Dir function ensures that Dir only returns the names of files; directories are ignored. Note: While XNameAccess permits access to the individual objects, XNameContainer takes on the insertion, modification and deletion of elements. To display all information available from an object and link to the corresponding API documentation, use instead the Development Tools built into LibreOffice or MRI extension. If you want to find other matches for the string, the function also provides the opportunity to specify an optional start position from which LibreOffice Basic begins the search. If another error occurs, the system outputs a warning. A long integer variable can take up to four bytes of memory. A LibreOffice Basic object can, however, support several services. The number of elements in an array is not affected if you use Option Base 1, only the start index changes. The origin of the line is specified in the Location property, whereas the coordinates listed in the Size property specify the end point of the line. Any modifications made to the data within the spreadsheet will also be reflected in the assigned chart. VBA: The content of the procedure described here for accessing the paragraphs of a text is comparable with the Paragraphs listing used in VBA, which is provided in the Range and Document objects available there. Note: It is, rather, the start index which moves in LibreOffice Basic. libreoffice basic programming guide pdf By July 27, 2021 OpenOffice Basic . Event-Driven Macros This section describes how to assign Basic programs to program events. It provides the functions for the frame object of LibreOffice, under which all document windows are classified. Each page in the presentation is a slide. VBA: Unlike VBA, where you can only dimension dynamic arrays by using Dim MyArray(), LibreOffice Basic lets you change both static and dynamic arrays using ReDim. They can be displayed as 2D or 3D graphics (com.sun.star.chart.Dim3Ddiagram service). The data field must provide a PropertyValue structure for each option in which the name of the option is saved as a string as well as the associated value. The actual replacement process is finally implemented using the replaceAll method of the document object, which replaces all occurrences of the search expression. Use branching statements to restrict the execution of a code block until a particular condition is satisfied. In the following example, both module A and B have a Private variable called C. The Test function first sets the Private variable in module A and then the Private variable in module B. The simplest scenario is for the button to trigger a When Initiating event when it is clicked by a user. All the above debug tools work on a running program. Here we rename the first page of the drawing document. The division between visible program elements (View) and the data or documents behind them (Model) occurs at many places in LibreOffice API. Standard file names using this system begin with the prefix file:/// followed by the local path. The following path references the test.odt file in the doc directory on the C: drive: file:///C:/doc/test.odt The Map AppFont (ma) replaces the Twips unit to achieve better platform independence. This example shows how to connect to an existing data source. The LibreOffice API provides two options for creating objects. The function ensures that the variable is actually assigned the correct value regardless of the country-specific settings. These are available through the Rows and Columns properties of the spreadsheet object and support the com.sun.star.table.TableColumns and/or com.sun.star.table.TableRows services. (When listing the service name of a text field, uppercase and lowercase characters should be used in LibreOffice Basic, as in the previous example.). The outer loop refers to the paragraphs of the text. For example, most of the page properties described in #Spreadsheets can therefore be used not only in LibreOffice Calc, but also in LibreOffice Writer. Documents are opened, imported and created using the method StarDesktop.loadComponentFromURL(URL, Frame, SearchFlags, FileProperties) The first parameter of loadComponentFromURL specifies the URL of the associated file. Their respective logos and icons are also subject to international copyright laws. The SQL language is provided as a query language for users of SDBC. The getByIndex method returns a row object, which supports the com.sun.star.text.TextTableRow service. All drawing objects that can have a border line support the com.sun.star.drawing.LineStyle service. This service can be addressed in LibreOffice Basic using the global name StarDesktop. If you use ReDim with Preserve, you must use the same data type as specified in the original data field declaration. "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. The status information remains valid until the program encounters a Resume or On Error command, whereupon the information is reset. The simplest variant is a single-color fill. As Basic makes automatic type conversions, there is usually no problems using a constant in an expression. This Statement object then uses the executeQuery call to return the actual ResultSet. placeholders in both VBA and LibreOffice Basic. Like bubbles, the variables gradually migrate to the right position. This property receives a PropertyValue data field with the following settings: The following example shows how a printer can be changed and the paper size set with the help of the Printer property. Using these parameters, the user can open a LibreOffice document, since placeholders (dummy values) can be assigned to the last two parameters: The preceding call opens the test.odt file and displays this in a new window. This help section explains the most common functions of LibreOffice Basic. The expression Dim MyArray(3) declares an array that has four variables of the variant data type, namely MyArray(0), MyArray(1), MyArray(2), and MyArray(3). To do this, it first creates a TextCursor object which makes reference to the content of the table cell and then adapts the paragraph properties of the table cell. 3D charts usually also have a floor. If the cursor of LibreOffice is in a cell, then the name of that cell can be seen in the status bar. It could be for example, A247. If you close a dialog by clicking the OK button, the Execute method returns a return value of 1, otherwise a value of 0 is returned. The code is first checked for obvious errors and then executed line by line. The chart wall is the background of the coordinate system where the data is plotted. The language of LibreOffice Basic: Defines the elementary linguistic constructs, for example, for variable declarations, loops, and functions. In other terms, you may think of a struct as a record, or part of a record. To make the fill transparent, set the FillTransparence property to 100. The dispose method at the end of the code releases the resources used by the dialog once the program ends. The search expression sh.rt therefore can stand for both for, The character ^ marks the start of a paragraph. VBA: Different terminology for spreadsheets and their content is used in VBA and LibreOffice Basic. The type declaration symbol for a currency variable is @. The loop is terminated as soon as the hasMoreElements method returns the False value, signaling that the end of the text has been reached. The following explanations relate to working with text files (not text documents). Extensive examples are provided to help you quickly develop your own OpenOffice.org Basic programs. All characters that follow an apostrophe are treated as comments: Markers can only contain Latin letters, numbers, and underscores (_). Logical operators allow you to do operations on elements according to the rules of Boolean algebra. To use bitmap projection as a fill, you must set the FillStyle property to BITMAP. You can also assign the elements to an individual tab page (for example page 1). The grouping of control elements in LibreOffice Basic is only used to ensure a visual division by drawing a frame around the control elements. If the corresponding page does not exist, it is created and inserted in the drawing document by the insertNewByIndex method. In its simplest variant the MsgBox only contains text and an OK button: The appearance of the information box can be changed using a parameter. This example shows how you may define and use a struct, and how to reference the items within it, both with and without With. If the database is password protected, the example creates an InteractionHandler and opens the database connection using the ConnectWithCompletion method. More extensive navigation options, such as the possibility of modifying values, are therefore not included. In LibreOffice Basic, this is accomplished with the On Error or Resume commands. If the directory contains sub-directories or files, these are also deleted. Note: This list provides the following elements: You can also add the constants together to delete different information using a call from clearContents. An option button control element provides two properties: You can also use the following properties from the model of the option buttons: To combine several option buttons in a group, you must position them one after another in the activation sequence without any gaps (Model.TabIndex property, described as Order in the dialog editor). the property is unclear. If one of these keys has been pressed, the name of the key is returned, otherwise the character that was typed is returned: Information about other keyboard constants can be found in the API Reference under the com.sun.star.awt.Key group of constants. The color gradient is depicted using a hundred graduated individual colors (StepCount). It can be very difficult to locate errors of this kind in your code. As a function, CompatibilityMode() returns the Boolean value of the mode. LibreOffice Basic returns the name of the first directory entry found. therefore ensures that the text is preceded by a tab character (Unicode-value 9) and that a hard line break (Unicode-value 13) is added after the text. RectangleShape.String = "This is a test" If it finds the search term, it takes the part before the expression and writes it to the Result return buffer. This guide provides an introduction to programming with LibreOffice Basic. Cells cannot be formatted by column in LibreOffice Basic. If you want to delete directory (including its files) use the RmDir function. No assurances are, however, provided for whether these can also be used by the object in question. Furthermore, the SearchFlags parameter must be set so that the corresponding framework is created, if it does not already exist. A variation of the If statement is the If/Else clause: In this example, the variable B is assigned the value of 2 when A is greater than 3, otherwise B is assigned the value of 0. This allows Java to control and manipulate LibreOffice's text, drawing, presentation, spreadsheet, and database applications, and a lot more (e.g. For this purpose, the com.sun.star.sheet.TablePageStyle service provides the following properties: Whereas the previous section described the main structure of spreadsheet documents, this section describes the services that allow you to easily access individual cells or cell ranges. To split a string across two lines of code, add an ampersand sign (the concatenation operator) and the underscore continuation character at the end of the first line: To include a quotation mark (") in a string, enter it twice at the relevant point: LibreOffice Basic supports five basic types for processing numbers: Integer variables can store any whole number between -32768 and 32767. For example, if only the C:\SubDir1 directory exists, then a call. The option of creating sub-forms is also provided for this purpose. The method provides the result in the form of a string. A table consists of individual rows. LibreOffice dialogs and forms are based on an event-oriented programming model where you can assign event handlers to the control elements. If this is not the case, it must be determined using the preceding code. The database interface from LibreOffice is available in the LibreOffice Writer and LibreOffice Calc applications, as well as in the database forms. The following example changes the dimension of the initial array so that it can record 11 or 21 values: When you reset the dimensions of an array, you can use any of the options outlined in the previous sections. The third section moves beyond work with texts. To make this possible, data sources are accessed by drivers. VBA: When creating and inserting tables in a text document, objects similar to those available in VBA are used in LibreOffice Basic: The document object and a TextCursor object in LibreOffice Basic, or the Range object as the VBA counterpart. You can page through and search in the selected tables and queries, as well as change data records and insert new data records. VBA: While the type of a field in VBA is specified by a parameter of the Document.Fields.Add method, the name of the service that is responsible for the field type in question defines it in LibreOffice Basic. Similar to saving, documents are printed out directly by means of the document object. LibreOffice Basic lets you define parameters as optional, that is, if the corresponding values are not included in a call, LibreOffice Basic passes an empty parameter. The following keyboard events are available in LibreOffice Basic: Both events relate to logical key actions and not to physical actions. Only at run-time can you find out which properties or methods are available for an object. Note: After modification, the values must be transferred into the database using the updateRow()method. The values required (in the example, those from the CustomerNumber field) returns the ResultSet using the getString method, whereby the parameter 1 determines that the call relates to the values of the first column. The LINE_TOP value of the VertOrient property ensures that the upper edge of the text frame is at the same height as the upper edge of the character. Fill and line properties (com.sun.star.drawing.FillProperties and com.sun.star.drawing.LineProperties services) as well as the character properties (com.sun.star.style.CharacterProperties service) are provided for further formatting of the elements. Instead, to simplify code maintenance and troubleshooting, you should create another procedure to serve as an entry point for event handling - even if it only executes a single call to the target procedure. The following example shows how four lines of a mathematical expression can be linked: Note: This service provides the following properties: When you format sheets, you can define whether page elements are visible. The X-axis points in reverse direction from right to left. You specify the qualifiers in the With statement. ThisComponent returns the last previously active document. VBA: Through their ValueItemList property, list box forms provide a counterpart to the VBA property, ItemData, through which you can administer additional information for individual list entries. Unlike C++ or Delphi, the LibreOffice Basic compiler does not create executable or self-extracting files that are capable of running automatically. The possible values are: In addition to directly modifying cell content, LibreOffice Calc also provides an interface that allows you to insert, delete, copy, or merge cells. Note: Even though you can use these procedures in any module, it is best to limit their use to two modules. 13 for LibO, and 1.3, ch. The ForNext loop has a fixed number of passes. You can create and structure dialogs using the LibreOffice dialog editor: You can drag the control elements from the design pallet (right) into the dialog area, and define their position and size. The following example sets the page size of a drawing document which has just been opened to 20 x 20 centimeters with a page margin of 0.5 centimeters: Warning: In LibreOffice, various types of charts can be displayed in a stacked form. Line charts provide the following properties: Area charts (com.sun.star.chart.AreaDiagram service) support two X-axes, two Y-axes and one Z-axis. Large sections of the basic constructs of LibreOffice Basic are compatible with Visual Basic. The control elements available in forms are similar to those of dialogs. The com.sun.star.frame.XStorable interface, which is responsible for saving documents. If the corresponding sheet does not exist, it is created by the createInstance call and inserted in the spreadsheet document by the insertByName method. Here are a few examples: The following example shows how all empty lines in a text document can be removed with the help of the regular expression ^$: So far, this chapter has only dealt with text paragraphs and their portions. There is no type declaration symbol for Boolean variables. Line objects support all the general formatting services with the exception of areas. This includes the way in which file names are structured for LibreOffice documents, as well as the format in which files are saved. Pie charts (com.sun.star.chart.PieDiagram) do not contain any axes and cannot be stacked. You can also move data from the database window into text documents using the drag-and-drop function. Literals are enclosed between hash signs #. Text frames are considered to be TextContent objects, just like tables and graphs. Once the Dlg dialog object has been initialized, you can use the Execute method to display the dialog. LibreOffice Basic provides two methods for inserting comments in the program code: A comment usually includes all characters up to the end of the line. Note: Clicking on this symbol opens a text field, in which a comment on the current point in the text can be recorded. Finally, LibreOffice provides a mechanism for forms based on databases. To check if the contents of a cell contains a number or a string, use the Type property: The Cell.Type property returns a value for the com.sun.star.table.CellContentType enumeration which identifies the contents type of a cell. Using the DBG_ properties is a very crude method to discover the contents of an API objects. With the TypeEnd Type statements, you can define your own (non-UNO) structs: The Type definition is only a pattern or template, not a set of actual variables. To access the view of a control element form, you need the associated model. The endDialog method of the dialog is an improvement of endExecute. The objective of developing this interface was to provide access to as many different data sources as possible. Download PDF. When the dimensions of the data field are changed, all contents are lost. The following example creates a table with the help of the createInstance method described previously. However, unlike the old Application object, StarDesktop is primarily responsible for opening new documents. LibreOffice provides a whole range of predefined date and time formats. VBA: In VBA, the formatting properties of an object are usually spread over a range of sub-objects (for example, Range.Font, Range.Borders, Range.Shading, Range.ParagraphFormat). The starting point for establishing the text fields present is the TextFields list of the document object. For more in-depth information please refer to the OpenOffice.org BASIC Programming Guide on the Wiki. In its simplest form, the print call is: As in the case of the loadComponentFromURL method, the Dummy parameter is a PropertyValue data field through which LibreOffice can specify several options for printing. The interaction between the AnchorType (from the TextContent Service) and VertOrient (from the BaseFrameProperties Service) properties should be noted here. A control element of a form has three aspects: The models of the control elements of a form are available through the GetByName method of the Object form: The example determines the model of the MyListBox control element, which is located in the first form of the text document currently open. Regardless of this, the original methods are also available (in our example, getPosition and setPosition). A drawing object for a spreadsheet document, for example, can therefore only exist in conjunction with this one document. Buy a printed copy. The same also applies to the maximum number of elements possible per dimension. The previous example creates a bar chart. The example creates a TextTables list containing all tables of a text that are traversed in a loop. The replacement function of LibreOffice is particularly effective when used in conjunction with regular expressions. This code inserts the test.jpg graphic and adapts its appearance using the Adjust properties. Whereas previously there was an object called SearchSettings especially for defining the search options, in the new object searches are now performed using a SearchDescriptor or ReplaceDescriptor object for automatically replacing text. If assignment is successful, the function returns True. Information about how to create, open, save and print documents is described in #Working with Documents, because it can be used not only for text documents, but also for other types of documents.

Marsha Soffer Rappaport, Words To Describe My Granddaughter, Tatooine Traders Lightsaber Vs Savi's Workshop, Ups Corporate Hr Phone Number, Percy Jackson Monologue, When Is Cirque Du Soleil Coming Back To Australia, Roger Huntsman Freddie Mills, Largest Transfer Of Wealth Covid, Patrick Flanagan Cause Of Death,

libreoffice basic programming guide pdf