LibreOffice provides an Application Programming Interface (API) that allows controlling the LibreOffice components with different programming languages by using the LibreOffice Software Development Kit (SDK). For more information about the LibreOffice API and the Software Development Kit, visit https://api.libreoffice.org. LibreOffice is the default office suite of most popular Linux distributions. It is the most actively developed free and open-source office suite, with approximately 50 times the development activity of Apache OpenOffice, the other major descendant of OpenOffice.org.Latest version
- LibreOffice Extensions, Documentation and Templates repository. MRI is an introspection tool of UNO objects, written in Python. If you want to know about UNO objects, try to use MRI. Targets of this extension are macro, extension developer and so on. MRI is an UNO service so that it can be used easily from any other languages.
- I have an appication in which I fill the LibreOffice text document using bookmarks and then save them as PDF (C#,.NET 4.0, VS 2010). I am facing the problem that when I fill the document first time then everything works fine but when I close the document using API and open new document and try to fill ( Automatically using Uno API) then Uno API process won't get response from LibreOffice.
Pythonic interface to Apache OpenOffice API (UNO)
PyOO allows you to control a running OpenOffice or LibreOfficeprogram for reading and writing spreadsheet documents.The library can be used for generating documents in variousformats – including Microsoft Excel 97 (.xls),Microsoft Excel 2007 (.xlsx) and PDF.
The main advantage of the PyOO library is that it can use almost anyfunctionality implemented in OpenOffice / LibreOffice applications.On the other hand it needs a running process of a office suiteapplication which is significant overhead.
PyOO uses UNO interface via Python-UNO bridge. UNO is astandard interface to a running OpenOffice or LibreOfficeapplication. Python-UNO provides this interface in Python scripts.Direct usage of UNO API via Python-UNO can be quite complicatedand even simple tasks require a lot of code. Also many UNO callsare slow and should be avoided when possible.
PyOO wraps a robust Python-UNO bridge to simple and Pythonicinterface. Under the hood it implements miscellaneousoptimizations which can prevent unnecessary expensive UNOcalls.
- Opening and creation of spreadsheet documents
- Saving documents to all formats available in OpenOffice
- Charts and diagrams
- Sheet access and manipulation
- Cell merging
- Number, text, date, and time values
- Cell and text formating
- Number formating
If some important feature missing then the UNO API is always available.
PyOO runs on both Python 2 (2.7+) and Python 3 (3.3+) but latest LibreOfficereleases are likely to support Python 3 only.
The only dependency is the Python-UNO library (imported as a module uno).Unfortunately Python-UNO cannot be installed using pip.Do NOT install package named uno available on PyPI - it’s not related to LibreOffice.
Debian / Ubuntu
On Debian based systems Python-UNO can by installed as python3-uno package.
Obviously you will also need OpenOffice or LibreOffice Calc.On Debian systems it is available as libreoffice-calc package.
Libreoffice Unoconv Windows
Install LibreOffice, for example using cask:
Then use Python binary bundled with the installed application:
PyOO library can be installed from PYPI using pip.:
If you downloaded the code you can install it using the setup.py script:
Alternatively you can copy the pyoo.py file somewhere to your PYTHONPATH.
Starting OpenOffice / LibreOffice
PyOO requires a running OpenOffice or LibreOffice instance whichit can connect to. On Debian you can start LibreOffice froma command line using a command similar to:
The LibreOffice will be listening for localhost connectionon port 2002. Alternatively a named pipe can be used:
If the --headless option is used then no user interface isvisible even when a document is opened.
For more information run:
It is recommended to start directly the soffice binary.There can be various scripts (called for example libreoffice)which will run the soffice binary but you may not get thecorrect PID of the running program.
PyOO acts as a bridge to a OpenOffice.org program so a connectionto the running program has to be created first:
Host name and port number used in the example ('localhost', 2002)are default values so they can be omitted.
Connection to a named pipe is also possible:
New spreadsheet document can be created using Desktop.create_spreadsheet()method or opened using Desktop.open_spreadsheet():
If the office application is not running in the headlessmode then a new window with Calc program should open now.
Spreadsheet document is represented by a SpreadsheetDocument class whichimplements basic manipulation with document. All data are in sheetswhich can can be accessed and manipulated via SpreadsheetDocument.sheetsproperty:
Cells can be accessed using index notation from a sheet:
All the changes should be visible in the opened document.
Every operation with a cell takes some time so setting all values separatelyis very ineffective. For this reason operations with whole cell rangesare implemented:
Miscellaneous attributes can be set to cells, cell ranges and sheets(they all inherit a CellRange class). Also note that cell rangessupport many indexing options:
Number format can be also set but it is locale dependent:
Charts can be created:
The first argument is a chart name, the second argument specifieschart position and the third one contains address of source data(it can be also a list or tuple). If optional row_header orcol_header keyword arguments are set to True then labelswill be read from first row or column.
Existing charts can be accessed either by an index or a name:
Chart instances are generally only a container for diagrams which specifyhow are data rendered. Diagram can be replaced by another type while chartstays same.
Diagram instance can be used for accessing and setting ofmiscellanous properties.
Libreoffice Unique Values
Spreadsheet documents can be saved using save method:
And finally do not forget to close the document:
Automated integration tests cover most of the code.
The test suite assumes that OpenOffice or LibreOffice is running andit is listening on localhost port 2002.
All tests are in the test.py file:
This library is released under the MIT license. See the LICENSE file.
Release historyRelease notifications RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pyoo-1.4-py2-none-any.whl (19.1 kB)||File type Wheel||Python version py2||Upload date||Hashes|
|Filename, size pyoo-1.4.tar.gz (31.3 kB)||File type Source||Python version None||Upload date||Hashes|
Hashes for pyoo-1.4-py2-none-any.whl
Hashes for pyoo-1.4.tar.gz