Libreoffice Uno

Posted onby admin

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
  1. 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.
  2. 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.

Released:

Pythonic interface to Apache OpenOffice API (UNO)

Project description

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.

Available features:

  • Opening and creation of spreadsheet documents
  • Saving documents to all formats available in OpenOffice
  • Charts and diagrams
  • Sheet access and manipulation
  • Formulas
  • Cell merging
  • Number, text, date, and time values
  • Cell and text formating
  • Number formating
  • Locales

If some important feature missing then the UNO API is always available.

Prerequisites

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.

macOS

Libreoffice Unoconv Windows

Install LibreOffice, for example using cask:

Then use Python binary bundled with the installed application:

Installation

PyOO library can be installed from PYPI using pip.:

If you downloaded the code you can install it using the setup.py script:

Uno

Alternatively you can copy the pyoo.py file somewhere to your PYTHONPATH.

Usage

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.

Accessing documents

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.

Libreoffice Uno

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.

Sheets

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:

Formating

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

Charts can be created:

Libreoffice Unpkg

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.

Saving documents

Libreoffice Unique Values

Spreadsheet documents can be saved using save method:

And finally do not forget to close the document:

Testing

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:

License

This library is released under the MIT license. See the LICENSE file.

Release historyRelease notifications RSS feed

1.4

1.3

1.2

1.1

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyoo, version 1.4
Filename, sizeFile typePython versionUpload dateHashes
Filename, size pyoo-1.4-py2-none-any.whl (19.1 kB) File type Wheel Python version py2 Upload dateHashes
Filename, size pyoo-1.4.tar.gz (31.3 kB) File type Source Python version None Upload dateHashes
Close

Hashes for pyoo-1.4-py2-none-any.whl

Hashes for pyoo-1.4-py2-none-any.whl
AlgorithmHash digest
SHA256761a3c85cb6c0ee16e36e72280bd5773bac2c2037dd9892d128107a14efef4bc
MD5a37a53402374eca930af1431f31b1d3a
BLAKE2-256adeeda8fac6764111e52b4411f0fe93d78992bac18292fb844c85ba23ed6d47e
Close

Hashes for pyoo-1.4.tar.gz

Hashes for pyoo-1.4.tar.gz
AlgorithmHash digest
SHA2563e9fb17a616edfdccd122dbaa0e75e86c754f7641470141a5019efcc2d11b2af
MD5f8b3264a8cbb2025e7d693f0583b2232
BLAKE2-2561c8dbad1060f2fe8ec3e8f3bcf7013c615c910893e6e97a5e23a89cad7a3676e