-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the Au3LibreOffice wiki!
This article uses material from the Wikipedia article "LibreOffice" and other Wikipedia articles, which are released under the Creative Commons Attribution-Share-Alike License 4.0.
|
This UDF (AU3LibreOffice) is meant to aid the user in creating and manipulating LibreOffice Documents using LibreOffice's API. LibreOffice (L.O. for brevity) is a large office suite, and it has been no easy task to make this UDF available. With the size of the project, and the complexity of the underlying L.O. API, trying to have the end result be comprehensible to the user, with straight forward and simple usage has been striven for, but I fear not achieved. This wiki article hopes to help clear up some of the unknowns, and give some basic principles and tips on how to get started with automating LibreOffice. It also hopes to point out some differences between automating the Microsoft Office and LibreOffice suites, for those more familiar with automating MS Office products through AutoIt. It is not intended to explain LibreOffice's API, or how to use the API directly, though it will touch on some of that in explaining what this UDF does.
This wiki article assumes the user is at least comfortably experience with AutoIt, and has a general understanding and familiarity of LibreOffice, and how to use it manually, at least the component you intend to automate.
LibreOffice is a free and open-source office productivity software suite developed by The Document Foundation (TDF).
It was created in 2010 as a fork of OpenOffice.org, itself a successor to StarOffice.
The suite includes applications for word processing (Writer), spreadsheets (Calc), presentations (Impress), vector graphics (Draw), database management (Base), and formula editing (Math).
It supports the OpenDocument format and is compatible with other major formats, including those used by Microsoft Office.
OpenOffice.org (OOo), is a discontinued open-source office software suite, originally based on StarOffice.
Apache OpenOffice (AOO), is a derivative of OOo by the Apache Software Foundation.
It is not the intent of this article to go into any kind of depth, nor exhaust the topic of the differences between LibreOffice and Open Office, and their history. The user can, if interested, find much better documentation and explanations online for this subject. However, with that said, I will attempt to give a brief overview of the histories of the two suites, and their predecessors and derivatives.
The roots of OpenOffice, and consequently LibreOffice date back to roughly 1985, though not under the same name. In 1985 a word processing application was released named "StarWriter" by Marco Börries, who then formed a company named Star Division. By 1994, and version 2.0, the program came to be an office suite, named StarOffice, and including Base (Database management), Calc (Spreadsheets) and Writer (Word processing). StarOffice eventually came to have the same 6 basic elements modern successors have, namely: Base for Database management, Calc for spreadsheets, Draw for vector graphics, Impress for slideshows, Math for Mathematical formulas, and Writer for word processing. The office suite was initially offered as proprietary software until 1998, when it was first offered for free for personal use.
In 1999 Sun Microsystems purchased the StarOffice copyright and company, claiming it was cheaper to purchase StarOffice than to purchase 42,000 Microsoft Office licenses for Sun Microsystem's employees. The following year (2000), Sun released the suite as a free and open source program known as OpenOffice.org, marketed as a free alternative to Microsoft Office. At the same time Sun Microsystems offered the StarOffice program as a proprietary office suite based on snapshots of OpenOffice.org versions, with added features.
In 2010 Sun Microsystems was acquired by Oracle, which for roughly a year afterward released the office suite as Oracle OpenOffice, though development was significantly hindered by Oracle when they drastically cut down the development team for the suite. This decrease in active development, both by Oracle and the community, as well as concerns about the management of the project by Oracle, resulted in the majority of the community contributors leaving OpenOffice development and forming the group known as The Document Foundation, the significance of which will be touched on shortly.
In 2011 Oracle completely ceased development of Oracle OpenOffice, dismissing the remaining employees, and donating the rights and codebase to Apache Software Foundation, which resulted in OpenOffice being again renamed, this time to Apache OpenOffice. Apache OpenOffice continued development from 2011 until this day, though due to fewer contributors and developers actively working on the project, development has largely halted. In August 2025, Apache Software Foundation reportedly allowed the trademark for OpenOffice to lapse.
Along the way there has been several forks of OpenOffice and LibreOffice, some of these are Go-OpenOffice, IBM symphony, NeoOffice, and Collabora Office. As of 2025, most of these are no longer actively developed. Go-OO development was discontinued in favor of contributing to the then newly created LibreOffice, IBM Symphony was discontinued and the codebase was donated to Apache OpenOffice, and NeoOffice was announced as no longer active in 2024, according to Wikipedia. Collabora Office is an online version of LibreOffice that is more aimed at commercial usage, and development is still active as of 2025.
As already mentioned, after Oracle acquired OpenOffice.org in 2010, members of the OpenOffice.org community formed an organization called The Document Foundation. The Document Foundation aimed to continue development of OpenOffice.org under a fairer governance and contribution model, and at the same time announced a fork named LibreOffice. Since then to this time, LibreOffice has been being actively contributed to and developed. Thanks to partner organizations that focus more on paid support of commercial usage of LibreOffice or derivative versions, plus an active and contributing community, LibreOffice has been able to have more consistent and sustained development and maintenance than Apache OpenOffice was able to maintain. For these reasons LibreOffice is currently recognized as the more prominently active and used successor of OpenOffice.
With the above vague history, it will be easy to see that generally speaking, OpenOffice and LibreOffice have the same foundational features,but given the fact that LibreOffice is more actively developed, LibreOffice has more, and newer features available. This is also the reason this UDF was based on LibreOffice, and not OpenOffice.
Because LibreOffice is a fork from OpenOffice, this UDF will, in many places, work with OpenOffice as well. Unfortunately, as this UDF was being developed, I did not keep a record of the methods and properties that indicated they were added in certain LibreOffice versions, as well as the ones that seem to be not documented. Trial and error is the best method for now, with the addition of saying that any functions that list a minimum LibreOffice version, will most likely NOT be compatible with OpenOffice.
Sources:
- StarOffice - Wikipedia
- OpenOffice.org - Wikipedia
- Apache OpenOffice - Wikipedia
- LibreOffice - Wikipedia
The AU3LibreOffice UDF is a wrapper for the complex LibreOffice object model. It hides the complexity of the object model and replaces it with a few AutoIt function calls.
The functions provided by the UDF aim to cover most of the functionality that is typically required. However, if more complex functions are needed, you will have to write them yourself. The first step would be to familiarize yourself with the LibreOffice API. The following books will be a valuable help also in this line.
This page compares the features of LibreOffice and Microsoft Office in several form factors.
The comparisons separate major and minor feature differences and also includes notes on LibreOffice extensions.
The comparison highlights differences and therefore does not display any features which are present in both office suites.
For those users of this UDF that have a familiarity with Microsoft Office, it has been decided that it would be a good idea to include some comparisons between the two suites' APIs and internal behaviour to aid those familiar with MS Office's automation API, to be able to use this UDF and LibreOffice's API better.
As mentioned before, the starting point between LibreOffice and Microsoft Office are similar, but not identical.
In Microsoft Office, you always begin with a Microsoft Word, Excel or Powerpoint Application object, which is an instance of the respective component without a Document, Book, or presentation opened in it yet. The application instance is then used to create, connect or open Documents, Books or Presentations, or to set global settings. The Application instance when created can be either visible or invisible.
In LibreOffice you always begin with what is called a “ServiceManager”, this is essentially the equivalent of the Word, Excel or Powerpoint application Object, and is used to open, create or connect to Documents, Sheets or Presentations as needed. The ServiceManager, when created, has no visible UI.
The UDFs included with AutoIt for MS Word and MS Excel include separate functions for creating an instance of the corresponding Application Object, _Word_Create and _Excel_Open, because the Application objects are unique for each component, e.g., an Excel Application is used solely for working with Excel files and settings, etc. On the other hand, in this LibreOffice UDF, the user is saved steps of initializing the ServiceManager, as the ServiceManager is used alike for all the different components of LibreOffice (Base, Calc, Writer, etc.). The ServiceManager is “aware” of all opened Documents in the several LibreOffice Components, and can create instances of any component type, as needed. It can also open any appropriate Document in the correct component as needed. When the user calls for the first time *_DocCreate, or *_DocConnect, or *_DocOpen, or any similar functions, the ServiceManager is initialized in the background, and stored as a static variable for use in the UDF when needed.
MsOffice Word uses two types of data selections, the first is called a “Selection”, which is the visible selection you create in the Word application using your keyboard or mouse (Or also using the API). The second type is called a “Range”, and is an invisible or background selection of data, created solely using the API. Both support similar methods for extending or collapsing the selection, and have similar properties. A Range is able to be extended, or the beginning and ending position is able to be moved nearly the same as a Selection is, except a Range cannot be extended or moved by visual or on-screen lines, only structural units (paragraphs, sentences, etc.). There can be only one instance of a Selection at once, but you can have multiple Ranges at one time.
In LibreOffice Writer you also have two primary types of data selections. The first type of selection or “cursor” as it is generally known, is internally known as a “ViewCursor”, which is visible to the user. The second type of selection or “cursor” is called a TextCursor, and is invisible to the user.
A ViewCursor is what you see when you select some data in the document, and is also located wherever the caret is placed in the document. A ViewCursor is “aware” of characters, lines (where you see a line breaks to go to the next line to fit the Document width), pages and screens (Your current view), as well as the start and end of the Document, it is "View dependent" for its usefulness. There can only be one ViewCursor existing in a document at one time. A ViewCursor can be used very similarly to a TextCursor for the purpose of inserting or retrieve text, inserting shapes or tables etc., as well as getting and setting properties.
The TextCursor on the other hand is always invisible to the user whether or not data is selected. The Text Cursor is “blind” to lines, pages and screens. A TextCursor can, like a ViewCursor “see” characters, but it is also aware of the start and ending of words, sentences and paragraphs, it is more "document dependent" for its usefulness. Unlike a ViewCursor, you can have as many TextCursors as needed in one document.
There is a third type of Cursor that I will mention here briefly, it is called a Table Cursor. It is, as you may have guessed, only used for manipulating Tables, whether for joining cells, coloring, or sizing rows and columns etc. A Table Cursor is only aware of the Table and its cells. It cannot transverse outside of the Table. It is aware of cells, and the beginning and ending of the Table. It can go be moved to a specific cell by name, and merge and split cells. It cannot insert or retrieve text, nor edit text attributes.
When retrieving the current selection(s) made by the user, i.e. a selected string of text, the resulting object is essentially identical to a TextCursor, and in this UDF a TextCursor is created matching the selection to be returned to lessen the number of cursor types to account for in other functions. If the selection is not just text, another type of Object will be returned, as described in the selection function.
In Microsoft Excel there exists two types of data selections. There is a Selection, which represents what the user has currently selected with the cursor, be it a single cell or a range of cells. Secondly, there are what is known as Ranges, a Range is a group of cells, such as A2 to C4, or even a single cell. Excel treats these two very similarly, a selection is essentially the same as a Range, but is visually selected.
Similarly, in LibreOffice there are two types of data selections. There are selections, which is what ever the user has selected with the cursor, this can be text within a cell, a single cell, a range of cells (e.g. A1 to B3) or several ranges of cells (e.g. A1:C3 and D3:F5). The second type is also called a Range, this can be either a single cell, a group of cells, or even the entire sheet is considered a Range.
Another difference it would be good to briefly touch upon, is the different line endings used between MS Office and LibreOffice. Microsoft Office, of course, uses the standard Windows CRLF (Carriage Return, Line Feed) hard newline sequence (when you push Enter while editing a document). And a LF (LineFeed) for a soft newline (when you push Shift+Enter in a document).
LibreOffice on the other hand uses the Unix style newline sequences, either CR (Carriage Return) or LF (Line Feed). The CR sequence is used for hard newlines, and the LF sequence is used for soft newlines. This generally won't be encountered nor cause much issue for the majority of tasks while automating LibreOffice. However it may become an issue when getting or inserting strings, particularly in Writer. For example, if I select several paragraphs and retrieve the text of those paragraphs for processing in AutoIt, and then replace those selected paragraphs with the text I processed in AutoIt, the resulting text will most likely not have the same amount of newlines, there would be a mixture of hard and soft newlines in the paragraph, where before there maybe was only hard newlines. The root cause for this seems to be due to the way strings are handled when retrieving them from LibreOffice, newlines use the platform default newline sequence when retrieving the string, instead of maintaining the current newline sequence used by LibreOffice, so when working on Windows, the CRLF is used for all hard newlines. This is generally only true of inserting and retrieving strings directly in the document, or any frames, textboxes, pr table cells in Writer. Caution should be exercised when inserting a string, to manually use the CR or LF sequences as needed when wanting to insert a hard or soft newline respectively.
Presently this UDF attempts to perform a find and replace operation for CRLF newlines to convert them to CR whenever strings are being set that allow newlines, and that may be affected by this issue. It is still recommended that the user does this themselves to ensure they obtain expected results. Calc does not seem to be affected by this issue, as it appears to convert any CR or CRLF to LF.
One more less important difference between MSOffice and LibreOffice is formatting. When formatting text in MS Office, usually the user uses what is called “Direct Formatting”, i.e., selecting some text and selecting Bold, to bolden the text, or italic, etc. Not that you can't and don't create and apply formatting styles, but primarily this is how MS Office intends the user to apply formatting and styling.
In LibreOffice however, the way the user applies formatting is intended to be slightly different. This is not to say that the user cannot use “direct formatting”, they can, and many do, but it sometimes does not produce desirable results when attempts are made later on to change this or that styling, often unsightly text ends up being produced, perhaps wrong text sizing when the font was made bigger, or words still in an old font style etc.
The way LibreOffice intends the user to apply formatting and styling is by the use of what is called Paragraph Styles and Character styles. Paragraph styles, of course, would be used to apply, for example, a certain font to an entire paragraph, they modify and apply their affects to the whole paragraph where they are applied, except when overridden by direct formatting. Character styles on the other hand, as their name implies, apply the styling only to the character(s) it is applied to, generally this is used to apply coloring, bold, underlining or italic to characters as needed, except where direct formatting is applied already.
Given the fact that LibreOffice also supports direct formatting as MS Office does, this difference isn't necessarily important. But for the best experience, both manually working with LibreOffice, and while automating it with this UDF, it is recommended to use the styling approach instead, or at least keep these facts in mind to you know what to expect.
Microsoft Office uses the COM (Component Object Model) model for Automation and Inter-Process Communication (IPC), whereas LibreOffice has inherited from OpenOffice.org a very similar model called UNO (Universal Network Object). While LibreOffice uses UNO, for automation on Windows using AutoIt, the COM model is still used externally and all communication is then passed through a bridge to interact with UNO internally. The reasons that a new model was created, and the differences between COM and UNO aren't really important to discuss here, but a few reasons why UNO was created are as follows: Platform Independence (works on Windows, Linux, Mac), Exception Handling, which is not natively supported by COM, and the large code generation needed, e.g., in COM etc., "results in huge libraries if there are many types. For each new bridge, new generated glue code would be necessary, which becomes too difficult to handle". But if you would like further information, you can begin at the following websites:
- https://www.openoffice.org/udk/common/man/uno_the_idea.html
- https://www.openoffice.org/udk/common/man/uno.html
- https://en.wikipedia.org/wiki/Universal_Network_Objects
- https://chris-sherlock.gitbook.io/inside-libreoffice/universal-network-objects
Currently there are no external requirements needed to run this UDF. The user is able to work with both the Installed version of LibreOffice and also the Portable version of LibreOffice. However do take note of the methods followed to work with the Portable LibreOffice to make sure it will fit your requirements.
- The ability to Automate LibreOffice Portable (and OpenOffice) has been added, and Should work correctly. However to achieve this, it currently adds some temporary Registry entries to HKEY_CURRENT_USER, unless there is an installed version of L.O. or O.O. present. See _LO_InitializePortable for more detail.
- This UDF has been written using the English version of LibreOffice, and some aspects may only work for the English version of LibreOffice installations without errors.
- Many functions in this UDF may or may not work with OpenOffice, and some are definitely for LibreOffice only. These unfortunately have not been documented.
- For those using AutoIt versions older than 3.3.16.1 some functions in this UDF use Maps, which will not be recognized as proper syntax in older AutoIt versions.
Some terminology you will encounter frequently in the UDF, and sometimes in these articles, are the following:
- Hundredths of a MM (HMM)
- As implied by the name itself, Hundredths of a MM is a hundredth part of a Millimeter, and is the measurement unit used by LibreOffice internally for nearly all widths, heights, distances, etc. For simplicity, this is the unit type used in this UDF as well, unless otherwise stated in the Parameters. A converter function has been supplied with this UDF, found in the “LibreOffice_Helper.au3" file, called _LO_UnitConvert. This function can convert from millimeters, centimeters or inches to HMM, and back again, depending on the flag called.
- Component
- Any component or module of LibreOffice. The L.O. Components are: Base, Calc, Draw, Impress, Math, and Writer.
- RGB color Integer
- A color unit you will find frequently in this UDF. LibreOffice nearly always uses this type of color value when setting or retrieving a color property. The RGB color integer is a number from 0 to 16,777,215, where each separate number represents a color. The relationship between RGB and a RGB Integer is based on a simple calculation: RGB Integer = Blue x (256 x 256) + Green x 256 + Red, or in Hexadecimal, 0x00RRGGBB, where RR = Red component (0-255), GG = Green component (0-255), BB = Blue component (0-255), and the highest byte (alpha) is unused and usually 0.
- UI
- User Interface, the visual windows and buttons and tabs the user sees and is used to work with LibreOffice manually.
LibreOffice uses a number of Styles for various things, such as Paragraph styling, Character styling, Table and Cell styling, etc. LibreOffice automatically translates these style names according to the user's default language currently set, these are called the “Display Name”. To enable Macros, as well as LibreOffice itself to work on any language system these style names are also internally named so that they can remain constant. In the English version of LibreOffice the Display Name and the Internal name, or “Programmatic Name” of every style is most cases the same. There are a handful of exceptions to this however, for example “Default Paragraph Style” is internally named “Standard”, “No Character Style” is also internally called “Standard”, (but is classed as a Character Style, not a Paragraph Style). There are a few others as well that I won't take the time to mention as each respective style name retrieval function lists any styles that have names differing from their internal names.
In previous versions this UDF automatically converted the internal names to the appropriate display names, and vice versa using a simple find and replace list, The problem with that method however was that it also restricted the UDF more to the English language.
Initially the automatic conversion between the names was more for user convenience, as it was found that either the Display name or the Internal name would work when setting the respective styling, and seemed to make no material difference. However as of LibreOffice 25.2 a certain bug was fixed, which it was found that LibreOffice was “Accidentally” accepting both the Display Name and the Internal name, and would also occasionally cause unpredictable issues. Therefore as of 25.2 this “bug” was fixed, which means that LibreOffice's API no longer accepts both the Display Name and the Internal name, but now only accepts the Internal or Programmatic name. Therefore this UDF has been modified to do the following:
- When retrieving current setting values, any style names are left as they are found in LibreOffice's API, as the Internal style name.
- When retrieving all available style names for a particular style set, the Internal name is returned, previously the Display name was returned.
- When setting stylings, as of LibreOffice 25.2 and up the Internal style name will likely only be accepted by LibreOffice. Previous to L.O. 25.2, both styling names should be accepted, though property setting errors may be triggered as the name will be automatically converted to the internal name by LibreOffice, and will not match the called display name in some cases.
- To aid the user in recognizing what Styles are which, each respective style name retrieval function offers the ability to still retrieve the Display name, which will be returned in the same order as the Internal names are returned, allowing the user to easily have a list of each name and see which belong to which. Further than this, as stated above, each respective style name retrieval function also lists any styles that have names differing from their internal names.
To use this UDF, the user can place the entire set of .au3 files of this UDF wherever the user is creating their script, or in a separate location elsewhere, and simply point the #Include to the appropriate location of the necessary files.
#include "C:\Autoit Scripts\LibreOffice_Helper.au3"No further installation or files are required.
With the exception of working with Portable LibreOffice (see the Portable LibreOffice section regarding this), the first step will always be to acquire a Document object. In order to obtain a Document Object, the beginning step is to either open an existing file by providing the file path to the appropriate function, for example an odt or docx file would be opened with Writer, or an ods or xlsx file would be opened by Calc, etc. Alternatively you could also connect to an already opened document instance using one of the “Connect” functions. Or, finally, you may just want to create an entirely new Document using the appropriate “Create” function. The actual process on how to do this will be discussed in more detail for each element in another section.
Once a Document object is acquired, you then go forward from there to accomplish the task you desire to do. We will touch on this shortly, but first it is important to deal with the most probable question on any newcomer's mind,
The first thing you are going to see when opening the UDf folder is a large number of files, named various things. How do you know which to use, which to include or not to include in your script? To begin with, the files are arranged in a semi-hierarchical form. Consider the following chart:
This chart illustrates part of the hierarchy, the file “LibreOffice.au3” has Includes in it for all sub-components. (Note: Some components in the chart aren't supported yet.). If you include this file, you can use any of the functions in all other sub-component files, all those listed in the chart. However, if you don't want such a large number of files included in your Script. You can include any sub-component you may need, such as LibreOfficeCalc.au3, or LibreOfficeBase.au3. Whichever component(s) you intend to automate.
Going a step further, consider this chart:
This chart considers only one component, in this case Writer. LibreOfficeWriter.au3 has many sub-files for the various tasks that can be done in Writer; Cell, Cursor, Doc, etc. More detail about these sub-files will be touched a little later. If you include LibreOfficeWriter.au3 in your script, you can use any of the functions in all the sub-files for Writer. You can identify a sub-file because the name will contain the Component's name, followed by an underscore, in this case, LibreOfficeWriter_*.au3., where “*” is a sub-file category of some type, i.e. Table, Doc or Page.
Lastly, you also have the option to include in your script only some of the sub-files themselves. This may be a better approach depending on how much you need to do. For example, if you only need to Export a document, one could potentially only include LibreOfficeWriter_Doc.au3, which would include all the needed functions for the task, such as *_DocOpen, *_DocExport, etc.
One small tip, you will never need to deal with the files named “*_Internal.au3”, i.e. LibreOfficeWriter_Internal.au3, they contain only functions needed by the various sub-files and are already included in the sub-files where needed.
Now we have reached the more interesting part, and also the more difficult. Most likely you have a certain task you need to accomplish, but how do you know what files you need for the job? Part of this problem we solved above, you (should) know already what component(s) of LibreOffice you want to automate, be it Calc, Base, or Writer, etc.Thus you know if you'll need to include LibreOfficeCalc.au3, LibreOfficeBase.au3 or LibreOfficeWriter.au3.
The next step is finding the right functions. This is admittedly the harder part to do, especially when you first begin with this UDF. We have attempted to logically sort functions according to their usage as best as possible. The naming of the sub-files is the first clue. Functions dealing with Document related actions, such as opening, closing, saving, maximize, minimize, visible/invisible, undo/redo, are found in the “*_Doc.au3” file. Taking Calc as an example, The LibreOfficeCalc_Sheet.au3 file has functions for adding or deleting Sheets from the document, setting and retrieving which Sheet is currently active, as well as retrieving the Object for the Sheets to use in further operations. There are also files for dealing with Ranges, as well as Cursors and Fields. This should help narrow down which file you will need to look through.
Next, open each sub-file that seems to be related and look at the “; #CURRENT#” header near the top of the script. This will have a list of all the functions contained in the file. With each function we have tried to include in the name a hint of the corresponding tab or section in the LibreOffice UI, if applicable, as well as, of course, the attributes the function will affect or the action it will perform. For example when setting background color or background gradient in L.O., these settings are found under the “Area” tab in most UI pages. The corresponding functions are some of the following: _LOCalc_CommentAreaColor and _LOCalc_CommentAreaGradient. In this case the functions all have to do with modifying a Calc Comment, Area is the Tab name when setting some of these properties, (Background Color or Gradient).
While these tips are generally correct, they aren't a solid rule yet. This UDF has attempted to adhere to this as best as possible, but LibreOffice has a wide variety of similar settings, not always located in identical settings. For example, for Cell background, there is no “Area” tab, thus the background color functions are simply _LOCalc_CellStyleBackColor and _LOCalc_CellBackColor.
Once you find the function you need to use, always check the parameters section in the header, it will aid in indicatating where to find what you need to use to call each parameter, or what kind or where to obtain the kind of Object you need. As an example, consider the following Parameter entries from _LOCalc_CellUnderline,
$oCell - [in/out] an object. A Cell Range or Cell object returned by a previous _LOCalc_RangeGetCellByName, _LOCalc_RangeGetCellByPosition, _LOCalc_RangeColumnGetObjByPosition, _LOCalc_RangeColumnGetObjByName, _LOcalc_RangeRowGetObjByPosition, _LOCalc_SheetGetObjByName, or _LOCalc_SheetGetActive function.This contains a few important details. First: The parameter $oCell accepts either a Calc Cell Range Object (i.e. a range Object covering A1:B3), Or a single Cell Object (i.e. Cell Object for Cell C3). Then follows a list of functions that would return such Objects that would be acceptable, this list is not always exhaustive when there are many functions that would return a similar acceptable Object or value. However the Object or value will either be named the same, or a note will be in the remarks section of the header indicating what else would be acceptable. Another example from _LOCalc_CellUnderline,
$iUnderLineStyle - [optional] an integer value (0-18). Default is Null. The Underline line style, see constants, $LOC_UNDERLINE_* as defined in LibreOfficeCalc_Constants.au3.This parameter has a few different and important details. First you will see some numerical values inside of parenthesis, 0-18, I will explain these shortly, you will also see it mentions a certain Constant name, in this case “$LOC_UNDERLINE_*”, this means, of course, that this parameter accepts the Constants of this name as values, the constants will be found in the file LibreOfficeCalc_Constants.au3. If you went to the Constants file, you would see 19 separate Constants to choose from. The values inside of the parenthesis means that this parameter accepts any of those constants that have values between 0 and 18.
$iULColor - [optional] an integer value (-1-16777215). Default is Null. The color of the underline, set in Long integer format. Can be a custom value, or one of the constants, $LO_COLOR_* as defined in LibreOffice_Constants.au3. Set to $LO_COLOR_OFF(-1) for automatic color mode.This parameter is similar, again some values are found in parenthesis, -1 to 16,777,215. However if you went to the constants indicated, you would see that they only have a few options to choose from, but not an exhaustive list ranging from -1 to 16,777,215. That is why the parameter description indicates you can choose any custom value between -1 and 16,777,215, you can make up your own value as desired as long as it falls between those two values. We will touch another Parameter from another function as a final example.
$iDistance - [optional] an integer value. Default is Null. The distance of the Shadow from the Comment box, set in 1/100th MM.Considering this Parameter, you will see that there are no parenthesis in this one, this generally means there are no limits, or perhaps only a minimum. If there is a minimum, and it is not mentioned in the parameter, it can be found by looking at the documented Input errors in the header. In this case, $iDistance has the following Input error:
@Error 1 @Extended 4 = $iDistance not an Integer, or less than 0.That means $iDistance must be an integer, and cannot be less than 0. But there is seemingly no maximum. Or perhaps the maximum varied, which would be noted in the Remarks section, but generally it means it is not present.
Throughout this UDF you will encounter functions that are for setting properties, whether it is Styles, Tables, Cells, etc. Usually, you will see that nearly all the parameters will be optional, except for the required Object parameter(s). The optional parameters will have an assigned value of “Null”, which will tell you that, unless indicted otherwise, this function can be used to both set AND retrieve the current property values. You can confirm if this is the case by looking at the Remarks section of the header for a statement similar to the following:
Call this function with only the required parameters (or by calling all other parameters with the Null keyword), to get the current settings.If you call this function with all optional parameters to Null the return will be an array (except when there is only one optional parameter, in which case the return will be of what ever type the Parameter is, an Integer, a String etc.) If there is more than one optional parameter, the returned array will be a single dimension (unless indicated otherwise), with each element of the array in the order of the optional parameters. For example:
_LOWriter_ParStyleBorderColor(ByRef $oParStyle, $iTop = Null, $iBottom = Null, $iLeft = Null, $iRight = Null)In this function you have the non-optional parameter, $oParStyle, and four optional parameters, $iTop, $iBottom, $iLeft, and $iRight. If I called this function with only a Paragraph Style Object, it would return the current Paragraph Style Border color values, the returned array would contain the following values: $aArray[0] = $iTop, $aArray[1] = $iBottom, $aArray[2] = $iLeft, and $aArray[3] = $iRight.
Furthermore, any functions that have optional parameters with the “Null” value assigned to them, means that you can also skip any parameters you do not want to set a value for by calling “Null” in the position, nothing will be modified for that property.
There are some files I have not yet touched upon in these explanations, which we will now examine. Each separate component has a file named *_Helper.au3, there is also a general file called LibreOffice_Helper.au3. These files contain functions that either don't fit under the other categories, or are purely for aiding in other work. For example there is in LibreOffice_Helper.au3 functions such as _LO_UnitConvert, and _LO_VersionGet. _LO_UnitConvert can be used for converting from common units of measurement to the measurement unit used by LibreOffice internally (100th MM). VersionGet is used to determine the current LibreOffice/OpenOffice version being automated. This is beneficial when certain functions or parameters are only available for certain L.O. versions (These limitations will be indicated in any applicable functions, either in the parameter, or the description of the function itself if the whole function is restricted to a certain version.).
Taking a look at LibreOfficeWriter_Helper.au3, we find some functions like the following: _LOWriter_FontsGetNames, and _LOWriter_SearchDescriptorCreate. _LOWriter_FontsGetNames, obviously, retrieves an array of all available Fonts for use in the Document. _LOWriter_SearchDescriptorCreate creates a Search descriptor Object for usage in the Writer Find and Replace functions found in the LibreOfficeWriter_Doc.au3 file.
Keeping in mind the information mentioned in the differences section, particularly the difference between Microsoft Office using Applications, and LibreOffice using a ServiceManager for Document management. Also how this UDF has chosen to spare the user from having to create the ServiceManager themselves for this UDF, instead creating the ServiceManager in the background, and storing it as a static variable. The exception to this method is when working with LibreOffice Portable. Obviously, the behind the scenes method of using ObjCreate for creating the ServiceManager wont work with portable LibreOffice because the COM server is not registered in the registry, which AutoIt relies upon to create COM Objects.
To work around this, and allow the user to work with Portable LibreOffice, this UDF has a single function found in the LibreOffice_Helper.au3 file, named _LO_InitializePortable. This function is used to point the UDF to the location of the Portable LibreOffice folder. Depending on whether there is an existing installation of LibreOffice or OpenOffice, one of two things occurs:
- If there currently is not an installed version of either LibreOffice or OpenOffice, and if the path called is valid, a temporary registry entry is added to the HKEY_CURRENT_USER Registry key (See __LO_SetPortableServiceManager for all keys created) mirroring the installed version's entries to allow AutoIt to create an instance of the ServiceManager. Once a ServiceManager has been created, the entries are deleted.
- If there is already an installed version of LibreOffice or OpenOffice, the ServiceManager is created using the already existing entry, and the registry remains unmodified.The reason this still works for the Portable version will be described next.
To debug your script, as with any AutoIt function, the first place to start is checking for @Error, and @Extended values after each function call. Each function in this UDF has error, extended and return values which are documented in the header of each function describing each of the error values combined with the extended value. This should give you a beginning to find out what is wrong, whether it is a wrong input value, or perhaps something is failing to be created by the UDF or LibreOffice. When you encounter an error, the first step is to look in the header of the function that failed, and find the matching @Error and @Extended values to see what specifically has failed.
Currently there are 6 types of errors, the following is a brief description of each:
- 1. Input errors. These, of course, indicate the user has input the wrong type of data, or an out-of-bound value. Make sure to re-read the parameters and any appropriate remarks for what is expected.
- --Input Errors--
- @Error 1 @Extended 1 Return 0 = $sFilePath not string, or file not found.
- 2. Initialization errors. These mean that the UDF failed to create some Object or other necessary item for use in a certain function, usually the error description should specifically indicate what item it was, to aid in tracking it down. These types of errors are generally out of the user’s control, and may indicate something has changed with LibreOffice that has caused this UDF to no longer function appropriately. One option however is to try again, sometimes it is simply a random incident, or perhaps a restart of the computer may help.
- --Initialization Errors--
- @Error 2 @Extended 1 Return 0 = Failed to create ServiceManager Object
- 3. Processing errors. These errors indicate that the UDF failed to perform some action, whether it was inserting something, calculating something, or retrieving something. Again, this type of error is largely out of the control of the user, and may be something wrong with the UDF itself, or perhaps with LibreOffice. Trying again is the best bet, but also double check that any input values are appropriate for what you are doing in the function that is failing. If you feel confident enough, you could try tracking down what specifically is failing to work in the UDF. If you find anything, make sure you file a issue report on the forum or GitHub page.
- --Processing Errors--
- @Error 3 @Extended 1 Return 0 = No open Libre Office documents found.
- 4. Property Setting errors. These indicate that the function failed, seemingly, to set the requested property values. When these occur, usually the function has still completed its main task successfully, such as inserting a new object, but has failed to set certain properties. Which properties have failed will be indicated in the returned @Extended value, as a Bit value, this means that to determine what property or properties failed to be set you will need to us BitAND and compare the @Extended value with the listed possible values in the header.
...
- Name ..........: _LOCalc_DocOpen
- --Property Setting Errors--
- @Error 4 @Extended ? Return 0 = Some settings were not successfully set. Use BitAND to test @Extended for the following values:
- | 1 = Error setting $bHidden
- | 2 = Error setting $bReadOnly
- | 4 = Error setting $sPassword
- | 8 = Error setting $bLoadAsTemplate
- | 16 = Error setting $sFilterName
<syntaxhighlight lang="autoit">
Local $iProperty_Error = $__LO_STATUS_PROP_SETTING_ERROR ; (4)
_LOCalc_DocOpen("C:\Path\To\File\Doc.ods", False, False, False, "123", True, "calc8")
Local $iExtended = @extended
If (@error = $iProperty_Error) Then
If (BitAND($iExtended, 1) = 1) Then
MsgBox($MB_OK, "Property Error", "Failed to set ""$bHidden"" property.")
ElseIf (BitAND($iExtended, 2) = 2) Then
MsgBox($MB_OK, "Property Error", "Failed to set ""$bReadOnly"" property.")
ElseIf (BitAND($iExtended, 4) = 4) Then
MsgBox($MB_OK, "Property Error", "Failed to set ""$sPassword"" property.")
ElseIf (BitAND($iExtended, 8) = 8) Then
MsgBox($MB_OK, "Property Error", "Failed to set ""$bLoadAsTemplate"" property.")
ElseIf (BitAND($iExtended, 16) = 16) Then
MsgBox($MB_OK, "Property Error", "Failed to set ""$sFilterName"" property.")
EndIf
EndIf
</syntaxhighlight>- 5. Printer errors, these are errors that relate to the printer, whether when there were no printers found when retrieving the currently available printer names, or whether there was an issue when setting printer related settings in LibreOffice.
- --Printer Related Errors--
- @Error 5 @Extended 1 Return 0 = No default printer found.
- 6. Version errors. These relate to the current version of LibreOffice being too low for a specific function or parameter. Any version limitations are documented either in the function description, if the entire function is limited to a certain version, or else in the parameter description. When encountering these errors the only option to correct it is to either not use the function or parameter that requires a higher L.O. version, or to upgrade to a newer version of LibreOffice.
- --Version Related Errors--
- @Error 6 @Extended 1 Return 0 = Current Libre Office version less than 7.4.
A further step for debugging scripts is to monitor for COM errors, which can be triggered if something is failing on the LibreOffice side of things. To aid in monitoring for COM errors, this UDF has user-COM error functions that allow the user to have a custom user function be called each time a COM error is encountered, or optionally, to either display a MsgBox with the COM error details, or output the COM error to the output using ConsoleWrite. Instructions for this are found in each respective COM Error function, _LO_ComError_UserFunction, _LOBase_ComError_UserFunction, _LOCalc_ComError_UserFunction, _LOWriter_ComError_UserFunction. Each component has its own dedicated COM user error handler, e.g., LibreOfficeWriter has the _LOWriter_ComError_UserFunction, LibreOfficeCalc has _LOCalc_ComError_UserFunction, and also LibreOffice.au3 has its own COM error handler also, called: _LO_ComError_UserFunction. This allows the user to further see when something is failing, and what may be the cause of the failure, and perhaps be able to correct it. The resulting COM error will always contain the following sections, Number, Description, At line, Source, Error Description, though it will not always have all of the values filled in. As an example, a COM error will look similar to the following:
! We intercepted a COM Error
Number: 0x80020006
Description: Unknown name.
At line: 199
Source:
Error Description:
! We intercepted a COM Error<br> Number: 0x80020009<br> Description: Exception occurred.<br> At line: 200<br> Source: [automation bridge] <br> Error Description: InterfaceOleWrapper::Invoke : <br> [automation bridge]UnoConversionUtilities<T>::variantToAny <br> Cannot convert the value of vartype :"8" to the expected UNO type of type class: 6 at C:\cygwin64\home\buildslave\source\libo-core\extensions\source\ole\unoconversionutilities.hxx:590<br> -2147352567 0
- Q. Why are there no Q&A's here?
- A. Because we haven't been frequently asked any questions yet.
While not necessarily a tool for aiding in using this UDF, XRAY is very handy for further automation using the LibreOffice API. XRAY allows the user to inspect the various properties and methods available for certain object.
- XRAY can be downloaded from: https://web.archive.org/web/20231002154509/https://berma.pagesperso-orange.fr/index2.html
Note The following instructions are best to be followed by users familiar with Macros and working with LibreOffice.
XRAY can be downloaded and installed by using the included "Install" macro with the ODT file that it is downloaded by.
Once installed, to enable the user to use the XRAY tool through AutoIt, a Macro such as the following can be placed in the "My Macros" library (not in a Document),to allow it to be available whenever Libreoffice is opened.
- Navigate to the "Edit Macros" window.
- Select Tools>Organize Macros>Basic
- On the new dialog that appears Select "Organizer"
- Select the "Libraries" tab.
- Make sure "My Macros & Dialogs" is selected for the "Location" value, and then select the "New" button.
- On the "New Library" dialog, enter the name for the library as "Debug". Select "ok".
- Select the "Modules" tab.
- On the "Module" heading, select the "Debug" Library, and then click "New".
- On the "New Module" dialog, enter the name "GetDebug", and Select "ok".
- Select the newly created "GetDebug" Module and select "Edit".
- Copy and Paste the following Macro into the edit page and click save.
REM -- LibreOffice Macro for using XRAY.
Function XrayThis(vObj)
If NOT GlobalScope.BasicLibraries.isLibraryLoaded("XrayTool") Then
GlobalScope.BasicLibraries.LoadLibrary("XrayTool")
End If
Xray vObj
End Function
The user can then use an AutoIt function such as the following to XRAY any Object of LibreOffice. (Note: You will need to update the Include path to the place where the UDF is stored.)
<syntaxhighlight lang="autoit">
#include "LibreOffice_Internal.au3"
Func __XRay($oObj)
Local Const $iURLFrameCreate = 8 ;frame will be created if not found
Local $iError = 0
Local $oDoc, $oServiceManager, $oDesktop, $oScript
Local $atProperties[3], $avParamArray[1], $aDummyArray[0]
Local $vProperty
Local $sFileURL = "private:factory/swriter"
ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
If Not IsObj($oObj) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$oServiceManager = ObjCreate("com.sun.star.ServiceManager")
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
$oDesktop = $oServiceManager.createInstance("com.sun.star.frame.Desktop")
If Not IsObj($oDesktop) Then Return SetError($__LO_STATUS_INIT_ERROR, 4, 0)
$vProperty = __LO_SetPropertyValue("Hidden", True)
If @error Then $iError = BitOR($iError, 1)
If Not BitAND($iError, 1) Then $atProperties[0] = $vProperty
$vProperty = __LO_SetPropertyValue("MacroExecutionMode", 4)
If @error Then $iError = BitOR($iError, 2)
If Not BitAND($iError, 2) Then $atProperties[1] = $vProperty
$vProperty = __LO_SetPropertyValue("ReadOnly", True)
If @error Then $iError = BitOR($iError, 4)
If Not BitAND($iError, 4) Then $atProperties[2] = $vProperty
$oDoc = $oDesktop.loadComponentFromURL($sFileURL, "_default", $iURLFrameCreate, $atProperties)
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 5, 0)
$oScript = $oDoc.getScriptProvider().getScript("vnd.sun.star.script:Debug.GetDebug.XrayThis?language=Basic&location=application")
If Not IsObj($oScript) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
$avParamArray[0] = $oObj
$oScript.Invoke($avParamArray, $aDummyArray, $aDummyArray)
$oDoc.Close(True)
Return ($iError > 0) ? SetError($__LO_STATUS_PROCESSING_ERROR, $iError, $oDoc) : SetError($__LO_STATUS_Success, 1, $oDoc)
EndFunc ;==>__XRay
</syntaxhighlight>MRI is a tool similar to XRAY, and is also still being maintained at the time of writing. I personally use the XRAY tool, but have heard many good things about MRI as well, and I believe both work equally well.
- MRI can be downloaded from: https://github.com/hanya/MRI/releases
Note The following instructions are best to be followed by users familiar with Macros and working with LibreOffice.
MRI has a Wiki page that provides installation instructions, found here. https://github.com/hanya/MRI/wiki
Once installed, follow the numbered directions for XRAY above, except copy and past the following macro instead.
REM -- LibreOffice Macro for using MRI.
Function MRIThis(vObj)
If NOT GlobalScope.BasicLibraries.isLibraryLoaded("MRILib") Then
GlobalScope.BasicLibraries.LoadLibrary("MRILib")
End If
Mri vObj
End Function
The user can then use an AutoIt function such as the following to MRI any Object of LibreOffice. (Note: You will need to update the Include path to the place where the UDF is stored.)
<syntaxhighlight lang="autoit">
#include "LibreOffice_Internal.au3"
Func __MRI($oObj)
Local Const $iURLFrameCreate = 8 ;frame will be created if not found
Local $iError = 0
Local $oDoc, $oServiceManager, $oDesktop, $oScript
Local $atProperties[3], $avParamArray[1], $aDummyArray[0]
Local $vProperty
Local $sFileURL = "private:factory/swriter"
ObjEvent("AutoIt.Error", __LOWriter_InternalComErrorHandler)
If Not IsObj($oObj) Then Return SetError($__LO_STATUS_INPUT_ERROR, 1, 0)
$oServiceManager = ObjCreate("com.sun.star.ServiceManager")
If Not IsObj($oServiceManager) Then Return SetError($__LO_STATUS_INIT_ERROR, 3, 0)
$oDesktop = $oServiceManager.createInstance("com.sun.star.frame.Desktop")
If Not IsObj($oDesktop) Then Return SetError($__LO_STATUS_INIT_ERROR, 4, 0)
$vProperty = __LO_SetPropertyValue("Hidden", True)
If @error Then $iError = BitOR($iError, 1)
If Not BitAND($iError, 1) Then $atProperties[0] = $vProperty
$vProperty = __LO_SetPropertyValue("MacroExecutionMode", 4)
If @error Then $iError = BitOR($iError, 2)
If Not BitAND($iError, 2) Then $atProperties[1] = $vProperty
$vProperty = __LO_SetPropertyValue("ReadOnly", True)
If @error Then $iError = BitOR($iError, 4)
If Not BitAND($iError, 4) Then $atProperties[2] = $vProperty
$oDoc = $oDesktop.loadComponentFromURL($sFileURL, "_default", $iURLFrameCreate, $atProperties)
If Not IsObj($oDoc) Then Return SetError($__LO_STATUS_INIT_ERROR, 5, 0)
$oScript = $oDoc.getScriptProvider().getScript("vnd.sun.star.script:Debug.GetDebug.MRIThis?language=Basic&location=application")
If Not IsObj($oScript) Then Return SetError($__LO_STATUS_INIT_ERROR, 2, 0)
$avParamArray[0] = $oObj
$oScript.Invoke($avParamArray, $aDummyArray, $aDummyArray)
$oDoc.Close(True)
Return ($iError > 0) ? SetError($__LO_STATUS_PROCESSING_ERROR, $iError, $oDoc) : SetError($__LO_STATUS_Success, 1, $oDoc)
EndFunc ;==>__MRI
</syntaxhighlight><syntaxhighlight lang="autoit">
#include <MsgBoxConstants.au3>
#include <File.au3>
#include "LibreOfficeBase.au3"
; Create a New, visible, Blank Libre Office Document.
Global $oDoc = _LOBase_DocCreate(True, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Create a new Base Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set the Database type.
_LOBase_DocDatabaseType($oDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set Base Document Database type. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a unique file name
Global $sSavePath = _TempFile(@DesktopDir & "\", "BaseDocTestFile_", ".odb")
; Save The Base Document To Desktop Directory.
_LOBase_DocSaveAs($oDoc, $sSavePath)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to save the Base Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Database Object.
$oDBase = _LOBase_DatabaseGetObjByDoc($oDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Retrieve the Base Document Database Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Connect to the Database
$oConnection = _LOBase_DatabaseConnectionGet($oDBase)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to create a connection to the Database. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Add a Table to the Database.
_LOBase_TableAdd($oConnection, "tblNew_Table", "Col1")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to add a table to the Database. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Close the connection.
_LOBase_DatabaseConnectionClose($oConnection)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to close a connection to the Database. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Save the changes to the document.
_LOBase_DocSave($oDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Save the Base Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Close the Base Document.
_LOBase_DocClose($oDoc, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Close the Base Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
</syntaxhighlight><syntaxhighlight lang="autoit">
#include <MsgBoxConstants.au3>
#include <File.au3>
#include "LibreOfficeCalc.au3"
; Create a New, visible, Blank Libre Office Document.
Global $oDoc = _LOCalc_DocCreate(True, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Create a new Calc Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the presently active Sheet.
Global $oSheet = _LOCalc_SheetGetActive($oDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve the currently active Sheet Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B1.
Global $oCell = _LOCalc_RangeGetCellByName($oSheet, "B1")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve B1 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set Cell B1's Text.
_LOCalc_CellString($oCell, "Sales")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B1 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B2.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "B2")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve B2 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set B2 Cell Value to 50
_LOCalc_CellValue($oCell, 50)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B2 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B3.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "B3")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve B3 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set B3 Cell Value to 15.50
_LOCalc_CellValue($oCell, 15.50)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B3 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell A5.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "A5")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve A5 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set Cell A5's Text.
_LOCalc_CellString($oCell, "Total")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B1 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B5.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "B5")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve A5 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set the Formula for Cell B5
_LOCalc_CellFormula($oCell, "=SUM(B2:B3)")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set Cell B5 Formula. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a unique file name
Global $sSavePath = _TempFile(@DesktopDir & "\", "CalcDocTestFile_", ".ods")
; Save The Calc Document To Desktop Directory.
_LOCalc_DocSaveAs($oDoc, $sSavePath)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to save the Calc Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Close the Calc Document.
_LOCalc_DocClose($oDoc, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Close the Calc Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
</syntaxhighlight><syntaxhighlight lang="autoit">
#include <MsgBoxConstants.au3>
#include <File.au3>
#include "LibreOfficeWriter.au3"
; Create a New, visible, Blank Libre Office Document.
Global $oDoc = _LOWriter_DocCreate(True, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Create a new Writer Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the visible document cursor (caret) to insert text with.
Global $oViewCursor = _LOWriter_DocGetViewCursor($oDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve the View Cursor Object for the Writer Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Insert some text at the ViewCursor.
_LOWriter_DocInsertString($oDoc, $oViewCursor, "Hello from LibreOffice, and AutoIt!")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to insert text. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a unique file name
Global $sSavePath = _TempFile(@DesktopDir & "\", "DocTestFile_", ".odt")
; Save The Document To Desktop Directory.
_LOWriter_DocSaveAs($oDoc, $sSavePath)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to save the Writer Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Close the document.
_LOWriter_DocClose($oDoc, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to close opened L.O. Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
</syntaxhighlight><syntaxhighlight lang="autoit">
#include <MsgBoxConstants.au3>
#include <File.au3>
#include "LibreOffice_Helper.au3"
#include "LibreOfficeCalc.au3"
#include "LibreOfficeWriter.au3"
; Update this path to match the path to your Portable LibreOffice/OpenOffice folder.
Global $sPathToPortable = "C:\Portable Apps\LibreOfficePortablePrevious"
; Initialize Portable LibreOffice
_LO_InitializePortable($sPathToPortable)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Initialize L.O. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a new Writer Document.
Global $oWriterDoc = _LOWriter_DocCreate(True, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Create a new Writer Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the visible document cursor (caret) to insert text with.
Global $oViewCursor = _LOWriter_DocGetViewCursor($oWriterDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve the View Cursor Object for the Writer Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Insert some text at the ViewCursor.
_LOWriter_DocInsertString($oWriterDoc, $oViewCursor, "Hello from LibreOffice, and AutoIt!")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to insert text. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a new Calc Document.
Global $oCalcDoc = _LOCalc_DocCreate(True, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Create a new Calc Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the presently active Sheet.
Global $oSheet = _LOCalc_SheetGetActive($oCalcDoc)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve the currently active Sheet Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B1.
Global $oCell = _LOCalc_RangeGetCellByName($oSheet, "B1")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve B1 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set Cell B1's Text.
_LOCalc_CellString($oCell, "Sales")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B1 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B2.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "B2")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve B2 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set B2 Cell Value to 50
_LOCalc_CellValue($oCell, 50)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B2 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B3.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "B3")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve B3 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set B3 Cell Value to 15.50
_LOCalc_CellValue($oCell, 15.50)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B3 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell A5.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "A5")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve A5 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set Cell A5's Text.
_LOCalc_CellString($oCell, "Total")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set B1 Cell content. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Retrieve the Object for Cell B5.
$oCell = _LOCalc_RangeGetCellByName($oSheet, "B5")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to retrieve A5 Cell Object. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Set the Formula for Cell B5
_LOCalc_CellFormula($oCell, "=SUM(B2:B3)")
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Set Cell B5 Formula. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a unique file name
Global $sSavePath = _TempFile(@DesktopDir & "\", "WriterDocTestFile_", ".odt")
; Save The Writer Document To Desktop Directory.
_LOWriter_DocSaveAs($oWriterDoc, $sSavePath)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to save the Writer Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Create a unique file name
$sSavePath = _TempFile(@DesktopDir & "\", "CalcDocTestFile_", ".ods")
; Save The Calc Document To Desktop Directory.
_LOCalc_DocSaveAs($oCalcDoc, $sSavePath)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to save the Calc Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Close the Writer document.
_LOWriter_DocClose($oWriterDoc, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to close opened L.O. Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
; Close the Calc Document.
_LOCalc_DocClose($oCalcDoc, False)
If @error Then Exit MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Error", "Failed to Close the Calc Document. Error:" & @error & " Extended:" & @extended & " On Line: " & @ScriptLineNumber)
</syntaxhighlight>