Unlike C and Java, arrays in Basic are declared and accessed using round braces and not square ones. Names() and surnames() are actually arrays. Rem replace.SearchRegularExpression = Trueįor n = lbound(names()) To ubound(names()) Replace = sheet.createReplaceDescriptor rem document.createReplaceDescriptor in case of Writer Surnames() = Array("Torvalds", "Stallman", "Anvin", "Kroah", "Gates")ĭocument = ThisComponent rem. Names() = Array("Linus", "Richard", "Peter", "Greg", "Bill") The following code sets the first cell in the first row to “Hola! Mundo”, the Spanish expression for “Hello! World”: Recipe 2: Change cell contentsĪnother often needed thing is the ability to change the cell contents. To run a macro from the editor, just place the cursor inside the sub or function body of any macro and press F5 (or alternatively, click the Run BASIC icon on the toolbar). Thus, any value across the entire spreadsheet can be fetched using this simple method. Cells can be referenced using the co-ordinate system where (0,0) refers to cell at row-0 and column-0. The important thing here is the expression, sheet.getCellByPosition(0, 0).String which gets the contents of first cell in the first row. ThisComponent is the LibreOffice object that references the current spreadsheet (or a written document in case of Writer). MsgBox(sheet.getCellByPosition(0, 0).String)ĭim is a keyword used to declare a variable but declaration is totally optional unless Option Explicit is specified at the beginning of the module. The following piece of code does exactly this: One of the most basic things needed for automation is reading a cell’s contents. This will open the LibreOffice Macro Editor as a separate window. After that, if you want to create a macro specific to your spreadsheet (as usually is the case), expand your spreadsheet file on left and select Standard and click New. To create a macro, just open the spreadsheet in LibreOffice and go to Tools->Macros->Organize Macros->LibreOffice Basic menu. Whilst macros can be created in Writer and Draw too, in this specific tutorial, we will restrict ourselves to spreadsheets (Calc). Recipe 0: How to create a LibreOffice macro
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |