Python Uno Libreoffice

admin

Since the upgrade to LibreOffice 4, I have been experiencing more crashes with messages such as “Binary URP bridge disposed during call” (which as far as I can tell means that an exception was thrown somewhere in LibreOffice) and other more standard exceptions. Typically they are non-repeatable.

Python Uno Bridge Libreoffice

LibreOffice Basic libraries contain classes, routines and variables, Python modules contain classes, functions and variables. Common pieces of reusable Python or UNO features must be stored in My macros within (User Profile)/Scripts/python/pythonpath. Python libraries help organize modules in order to prevent module name collisions. I made 'gettoday.py' like below, and copy to foler path as below. Then run code from menu ToolsMacrosOrganize MacrosPython, resluts are displayed in Calc. Sample scripts are in folder path as follow if you don't change default install path. C: Program Files (x86) LibreOffice 5 share Scripts python.

I have tried adding delays in my code (e.g. time.sleep(1) ), with what appears to be some small success. While normally you might think that this is a stupid idea that should do nothing, some of LibreOffice’s processing happens asynchronously (you tell it to do something, it tells you it’s done it, but actually it then does it a bit later). A good example of this is when updating indexes – I found that if you add a lot of pages to a document and then instantly create an index, it will create an index for a model of the document that is out of date. Delay for a few seconds first, and it will give you the correct index. Bad programming technique, but it works.

Python libreoffice calc

Libreoffice Python Uno Api

I have also found that having fewer LibreOffice windows open helps.

Python Uno Libreoffice Download

Libreoffice

Today I found a more reliable solution, which has had instant and obvious success: run LibreOffice in headless mode. So start LibreOffice (in server mode, to work with Uno) with the command:

Libreoffice Api

soffice --headless '--accept=socket,port=2002;urp;'

Python Uno Libreoffice Free

It has been working pretty well so far. YMMV.