The watch window of the Basic IDE can display the properties of a Uno object (but not the methods, not the interfaces). LibreOffice Basic Programming -- Resources for Learning English common, writer, calc, base, macro EssayFebruary 25, 2022, 3:17pm #1 H Everyone, Does anyone know of any books, pdf files, or courses where one can learn LibreOffice Basic and the ins and outs of macros in LibreOffice? 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. VBA: The page properties (page margins, borders, and so on) for a Microsoft Office document are defined by means of a PageSetup object at the Worksheet object (Excel) or Document object (Word) level. In this example, the counter begins at 10 and is reduced by 1 at the end of each pass until the counter is 1. You can page through and search in the selected tables and queries, as well as change data records and insert new data records. The ISO standard introduces new character sets (code pages) so that more languages can be correctly displayed. Forms are created using the Form Controls and the Form Design Toolbar directly within the document. To assign an explicit string to a string variable, enclose the string in quotation marks ("). Again an auxiliary structure, in this case com.sun.star.drawing.Hatch, is used to define the appearance of hatches. The ShapeCollection is added to the page using the Group method and returns the actual Group object that can be edited like an individual Shape. The Form Functions Toolbar is used for editing forms. The type declaration symbol for a long integer is &. By using ma units, LibreOffice ensures that a dialog looks the same on different systems under different system settings. It could be for example, A247. The computeFunction expects a constant as the parameter that describes the mathematical function that you want to use. The formatting properties can be found in each object (Paragraph, TextCursor, and so on) and can be applied directly. It uses the TextElement.String property in all paragraphs to access the relevant paragraphs and replaces the you, too and for strings with the U, 2 and 4 characters. The column objects support the com.sun.star.table.TableColumn service that has the following properties: The width of a column is only optimized when the OptimalWidth property is set to True. An integer variable can take up to two bytes of memory. You should also note the difference between text and numbers when you use formulas: Although cell A1 contains the value 100 and cell A2 contains the value 1000, the A1+A2 formula returns the value 100. Once the writing process has been completed, the file must be closed using a Close call: Again here, the file handle should be specified. However, these speed considerations no longer apply, reducing the need for single variables. The page properties that are valid for both types of documents are defined in the com.sun.star.style.PageProperties service. Here are a few examples of Variant variables: The variables declared in the previous example can even be used for different variable types in the same program. Currency variables are mostly intended for business calculations that yield unforeseeable rounding errors due to the use of floating point numbers. For a detailed description please refer to the LibreOffice Basic Guide which is available separately. In this example, the getByName method is used to find the bookmark required by means of its name. If you want to display the layout on screen, then you should create the associated LibreOffice Basic procedures so that they can be called up by the event handlers. The following example creates a rectangle shape and fills it with red (RGB value 255, 0, 0): If you set the FillStyle property to GRADIENT, you can apply a color gradient to any fill area of a LibreOffice document. A global Dlg variable that references an open dialog must be included to make this example possible. These provide the option of defining a variable search expression with placeholders and special characters rather than a fixed value. The following example declares a data field that has six integer values and which can be addressed using the indexes 5 to 10: The indexes do not need to be positive values. Forms, on the other hand, are displayed directly in the document, just like drawing elements. If a ResultSet is a SCROLL_INSENSITIVE or SCROLL_SENSITIVE type, it supports a whole range of methods for navigation in the stock of data. To make the fill transparent, set the FillTransparence property to 100. If there is another line inwards, it marks the transition to a filled area. 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. Whereas the document object in VBA is called a Workbook and its individual pages Worksheets, they are called SpreadsheetDocument and Sheet in LibreOffice Basic. In very rare cases, before calling up some property, use the IsEmpty function to check whether it is actually available. The following example shows a double loop which passes over all paragraphs of a text document and the paragraph portions they contain and applies the replacement processes from the previous example: The example runs through a text document in a double loop. The error sources noted for implicit type conversions can only be avoided by careful programming; for example, by not using the variant data type. Public domain variables are defined in the header section of a module by the keyword Dim. By using Option Compatible, LibreOffice Basic behaves like VBA. When you click a button that has this property set to the value of 0, the dialog remains unaffected. ), comma (,) and dollar sign ($) characters. The Model property provides program-controlled access to the model of dialog and control element objects. Note: For example, in the following variable declaration, MyVar1 becomes a variant and MyVar2 becomes an integer: The following sections list the variable types that are available in LibreOffice Basic and describe how they can be used and declared. Download PDF. The function returns a number that contains the position at which the StringToFind first appears within MyString; a return value of zero indicates no match. The type declaration symbol for an integer variable is %. It uses not only the Doc document object but also the DocCrl document controller object which makes reference to the current document window. This guide provides an introduction to programming with LibreOffice Basic. Note: When using DBG_properties, note that the function returns all properties that the services offered by the object can theoretically support. This function is not available in dialogs. In the latter examples, the code will be executed at least once. The following example creates a rectangle and tiles the Sky bitmap that is available in LibreOffice to fill the area of the rectangle: You can adjust the transparency of any fill that you apply. The Chart object provides the property Area to format the background: The background of a chart covers its complete area, including the area under the title, subtitle and legend. You will find another description of dialogs in the Developer's Guide: Browse to and select the macro you want to assign. Alternatively, if only an empty document without any adaptation is needed, a private:factory URL can be specified: The call creates an empty LibreOffice writer document. An instance of the new type is a variable, and follows the usual rules for variable scope (see #Scope and Life Span of Variables). The following example shows how to create a chart assigned to some cell ranges within a spreadsheet document: Although the code used in the example may appear to be complex, the central processes are limited to three lines. This chapter provides a background on the API. Whereas the dialog functions are available in all LibreOffice documents, the full scope of the form functions are only available in text and spreadsheets. Drawing objects include shapes (rectangles, circles, and so on), lines, and text objects. The areas can be stacked (com.sun.star.chart.StackableDiagram). The TextCursor objects available in LibreOffice Basic should not, however, be confused with the visible cursor. Finally, the following information symbols are available and can also be displayed by adding the relevant parameter values: The following call displays an information box with the Yes and No buttons (value 4), of which the second button (No) is set as the default value (value 256) and which also receives a question mark (value 32), 4+256+32=292. Date literals allow to specify unambiguous date variables that are independent from the current language. The type is declared in the same way as a variable declaration: If the return type is not specified (see first example of this page), the function returns a variant. 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. Whereas in VBA, the methods are applied to the corresponding Range object, in LibreOffice Basic they are applied to the associated Sheet object. More information about working with styles can be found in the '''#Default values for character and paragraph properties''' section in #Text Documents. If you want to administer a numerical value (for example a database ID) in addition to the natural language text, you must create an auxiliary data field that administers in parallel to the list box. Dialogs such as this one are described as modal because they do not permit any other program action until they are closed. If a style in the template has been changed, and you open a document created with that template, you will see a message asking whether to update the styles in the document. The hasByName and getByName methods are obtained from the com.sun.star.container.XNameAccess interface. You can open a dialog with the following code: CreateUnoDialog creates an object called Dlg that references the associated dialog. A LibreOffice Basic object can, however, support several services. The runtime library from LibreOffice Basic provides several fundamental functions for these tasks. When Var is 0, there is a match. 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. These in turn contain the various cells. The service recognizes the following properties: If these settings are changed, then all of the pages in the document are affected. A Boolean value is saved internally as a two-byte integer value, where 0 corresponds to the False and any other value to True. A program-controlled position change of a TextCursor object has no impact whatsoever on the visible cursor. A drawing object for a spreadsheet document, for example, can therefore only exist in conjunction with this one document. The lengths are specified in hundredths of a millimeter. The following example uses a recursive function to calculate the factorial of the numbers 42, -42, and 3.14: The example returns the factorial of the number 42 by recursively calling the CalculateFactorial function until it reaches the base condition of 0! The call must take place before the next navigation command, otherwise the values will be lost. The XNameContainer interface takes on the insertion, deletion and modification of subordinate elements in a basic object. LibreOffice automatically ensures that the relevant data is retrieved from the database, and that any changes made are written back to the database. The LibreOffice API has been structured so that as many of its parts as possible can be used universally for different tasks. Charts within spreadsheets can display the data from an assigned cell range within the spreadsheet. VBA: Whereas the structure of an object in VBA is defined by the class to which it belongs, in LibreOffice Basic the structure is defined through the services which it supports. Programmers who want to work directly with Java or C++ rather than LibreOffice Basic should consult the LibreOffice Developer's . The model object of a checkbox form provides the following properties: The model objects of text field forms offer the following properties: The model object of the list box forms provides the following properties: Note: Text fields can also be used as special currency and numerical fields as well as screen fields for special tasks. The same applies when using variant variables: Since variant variables may contain both numbers and strings, it is unclear whether variable A is assigned the number 2 or the string 11. The found expressions differ by up to two letters from the search expression: Note: The com.sun.star.frame.Desktop service, which is similar to the core service of LibreOffice. This example inserts a cells range that is two rows by two columns in size into the second column and row (each bear the number 1) of the first sheet (number 0) in the spreadsheet. This example uses the insertByIndex method to insert a new column into the fourth column position in the sheet (index 3 - numbering starts at 0). Example declarations for single variables: Double variables can store any positive or negative floating point numbers between 1.79769313486232 x 10308 and 4.94065645841247 x 10-324. Literals are enclosed between hash signs #. And a title for the X-axis was added. If you are interested in only the mouse click, your macro should ignore all calls where PopupTrigger is TRUE. The corresponding counterparts of the TextCursor object in LibreOffice are described in the following sections. These are: The code for saving a document can be extended by these options so that the document is only saved if the object has actually been modified and the file name is only queried if it is actually needed: The example first checks whether the relevant document has been modified since it was last saved. The pages of a drawing document are available through the DrawPages container. As in the old API from LibreOffice, searching and replacing text in the new API is also performed using the document object. Each of these formats has an internal number that is used to assign the format to cells using the NumberFormat property. If the database is password protected, the example creates an InteractionHandler and opens the database connection using the ConnectWithCompletion method. You can also create data sources and work with them using LibreOffice Basic. You can also have loops with an undefined number of passes. If it does, the method determines a corresponding object reference by using the getByName method and then saves the reference in a variable in Page. All other characters are inserted as escape coding in the URLs. It inserts a new sheet with the name specified by the first argument, at the position specified by the second argument. The declaration can only be made using the supplement As Boolean. However, this may have fatal consequences. The date is formatted here in accordance with the country-specific settings used on the system. Those format properties that refer to individual characters are described as character properties. The functions responsible are insertByName, removeByName and replaceByName. The following example shows how these can be used in conjunction with a TextCursor. 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. The text in the paragraph can be retrieved and modified using the String property: The example opens the current text document and passes through it with the help of the Enumeration object. This code uses the String-property of the rectangle to insert the text and the CharWeight and CharFontName properties from the com.sun.star.style.CharacterProperties service to format the text font. LibreOffice Basic provides a whole range of methods for reading and writing files. return the number of pages, words, or characters of a text. If you want to format the individual objects of a group, apply the formatting before you add them to the group. Changes made to the variables are retained when the procedure or function is exited: In this example, the value A that is defined in the Test function is passed as a parameter to the ChangeValue function. It returns the string produced in this way as the result of the replacement process. In other words, a variable exists from the moment that you include it in your code. In general, Basic does not look inside a container, such as an Object, to see what names might be defined there. If a document has one page and this is called Slide 1, then the following examples are identical. The corresponding properties are: The following program code shows how DBG_properties and DBG_methods can be used in real-life applications. = 1. The second parameter specifies the text that is to be saved as a line of the text file. VBA: A ResultSet containing the READ_ONLY and SCROLL_INSENSITIVE properties corresponds to a record set of the Snapshot type in ADO and DAO. In the first example, the sheet is accessed by its number (counting begins at 0). The ResultSet object provides Update methods for modifying values, which are structured in the same way as the get methods for retrieving values. VBA: The basic idea of search and replace in LibreOffice is comparable to that used in VBA. If this is not the case, it must be determined using the preceding code. As these control elements are based on the UnoControlEdit Uno service, their program-controlled handling is similar. In some cases the loop may only terminate when a condition is met within the loop. The code used in this example creates a Doc object that references the current presentation document and establishes the associated presentation object. In addition to the program code to be executed, an LibreOffice Basic program can also contain comments that explain the individual parts of the program and provide important information that can be helpful at a later point. LibreOffice Basic belongs to the family of Basic languages. Special cell formatting is handled by the com.sun.star.table.CellProperties 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. A date / time field (com.sun.star.text.textfield.DateTime) represents the current date or the current time. The minimum distance between the text edge of the drawing object is set to three millimeters. Since control element forms within the documents are administered like a special drawing element, there is also a, This page was last edited 13:55:11, 2022-12-07 by, Please note that all contributions to The Document Foundation Wiki are considered to be released under the. This is described in the #Database Forms chapter. LibreOffice treats cell content that is entered using the String property as text, even if the content is a number. The following example shows how the models of the control elements of a group can be iterated, exemplary displaying the states of all control elements in a given group: The code corresponds to the previous example for determining a simple control element model. You can access individual pages either through their number or their name. LibreOffice Writer supports the following types of styles: LibreOffice Calc supports the following types of styles: LibreOffice Impress supports the following types of styles: In LibreOffice terminology, the different types of styles are called StyleFamilies in accordance with the com.sun.star.style.StyleFamily service on which they are based. In the following example, variable I is the loop counter, with an initial value of 1. The same also applies to the maximum number of elements possible per dimension. To improve clarity, you should avoid using Option Base 1. The Form Functions Toolbar is also used to switch between modes. The color for the rear wall of the chart is set to white. However, whether the corresponding settings are based on template or direct formatting in the text is still unclear. All occurrences of the name, A * indicates that the preceding character may be repeated any number of times. Visit Andrew Pitonyak's web page to get the latest PDF and ODT files of his book As a statement, CompatibilityMode( value ) takes a Boolean value to set or clear the mode. Every control element has its own name that can be queried using the following model property: You can specify the title that appears in the title bar of a dialog with the following model property: You can query the size and position of a control element using the following properties of the model object: To ensure platform independence for the appearance of dialogs, LibreOffice uses the Map AppFont (ma) internal unit to specify the position and size within dialogs. The paragraphs can however be sequentially traversed with the help of the Enumeration object described in #Introduction to the API. The headers and footers of a document form part of the page properties and are defined using the com.sun.star.style.PageProperties service. This function creates directories and sub-directories. Use the following style when you make a type-bound variable declaration: The variable is declared as an integer type and can record whole number values. Finally the code sets the Label property of the control element to the New Label value. A string consists of a sequence of consecutive individual characters. This uses the query window to check the SQL commands typed and corrects simple syntax errors, such as those associated with uppercase and lowercase characters. There is also no limit to the number of drawing elements that you can add to a page. The same interface provides methods moveByName and copyByName. The example defines a procedure called Test that contains code that can be accessed from any point in the program. It first creates the com.sun.star.frame.Desktop service and then displays the supported properties and methods in message boxes. No distinction is made between uppercase and lowercase characters. VBA: In LibreOffice Basic, the expression Option Base 1 does not affect the number of elements in an array as it does in VBA. ThisComponent returns the last previously active document. This example shows how a text can be searched for the word "turnover" and the results formatted in bold type. Note: Paragraph portions displayed in bold type are marked using a HTML element when exporting. LibreOffice provides various ways of establishing database connections. You can also use the keyword Public instead of Dim to declare a public domain variable: A public domain variable is only available so long as the associated macro is executing and then the variable is reset. Unlike the data sources presented in the previous section, the database connection must therefore be re-established every time the program is restarted. A database is incorporated into LibreOffice by creating what is commonly referred to as a data source. The com.sun.star.frame.XStorable interface, which is responsible for saving documents. 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. Calculations with long integer variables are very fast and are particularly useful for loop counters. First it splits "Source" dividing it at all "Search", and joins the parts back with "NewPart". The replacement function of LibreOffice is particularly effective when used in conjunction with regular expressions. In addition to the properties for characters (com.sun.star.style.CharacterProperties service, refer to #Text Documents) and lines (com.sun.star.drawing.LineStyle service, refer to #Drawings and Presentations), it provides the following properties: For the primary axes grids and sub grids can be displayed, matching to the major and minor intervals. The named _blank value for the Frame parameter ensures that LibreOffice creates a new window for every call from loadComponentFromURL. If it does not have a URL or was opened in its read-only status, it is saved under a new URL. These variables are available to all the modules in their library: The value of variable A is not changed by the Test function, but is increased by one in the Flip function and decreased by one in the Flop function. The letter A stands for the column and the number 1 for the row. Strictly speaking, there are no table columns in LibreOffice. Whereas an ODBC data source only covers information about the origin of the data, a data source in LibreOffice also includes a range of information about how the data is displayed within the database windows of LibreOffice. Overview. In accordance with UNO philosophy, an Obj is described as a reference to an object which supports the com.sun.star.frame.Desktop service. All properties form part of the associated model objects. With the help of this controller object and the model of the control element, it then uses the GetControl method to determine the view (CtlView variable) of the control element form. The As keyword syntax, and the fact that a comma is not used, goes back to the roots of the Basic language. Functions LBound() and UBound() return respectively the lowest permitted index value and the highest permitted index value of an array. VBA: If a string in LibreOffice Basic contains a non-numerical value and if this is assigned to a number, LibreOffice Basic does not produce an error message, but stops converting the string at the first invalid character. The following example outlines the replacement process within a drawing: This code uses the first page of the document to create a ReplaceDescriptor and then applies this descriptor in a loop to all the pages in the drawing document. A LibreOffice form may adopt one of two modes: the draft mode and the display mode. In a similar way to the search window, the settings needed for a search can be set in the SearchDescriptor object.
Fairmount Children's Home Records, Judge Kevin Ross Family, Animal That Looks Like A Squirrel But Small, Spider Man: Reign Kingpin, Articles L