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. Project description. PyOO allows you to control a running OpenOffice or LibreOffice program for reading and writing spreadsheet documents. The library can be used for generating documents in various formats – including Microsoft Excel 97 (.xls), Microsoft Excel 2007 (.xlsx) and PDF. The main advantage of the PyOO library is that it can use almost any functionality implemented in OpenOffice / LibreOffice applications. Scripting LibreOffice with Python We were recently asked to automate some editing tasks for the Spotlight English editors who use LibreOffice Writer to prepare their episode copy. With LibreOffice's UNO (Universal Network Objects) component model, which has bindings to many programming languages, we were quite spoiled for choice.
- 1Introduction
- 2Tutorial
- 2.1PyUNO tutorial for Apache OpenOffice
Introduction
The Python-UNO bridge allows users to:
- use the standard Apache OpenOffice API from the well known Python scripting language.
- develop UNO components in Python (so that Python UNO components may be run within the Apache OpenOffice process and can be called from Java, C++ or the Apache OpenOffice built-in StarBasic scripting language).
- create and invoke scripts with the office scripting framework (OpenOffice.org 2.0 and later).
You can find the most current version of this document from https://www.openoffice.org/udk/python/python-bridge.html
Download
You can also download this documentation for off-line work.
Download pyuno-doc.zip ( less than 0.5 MB).
State
The Python-UNO bridge is feature complete, but has not been used extensively and therefore may contain some bugs. It is now integrated in the OpenOffice.org source trees. (OpenOffice.org 1.0.x is not supported.)
The documentation in its current state is targeted at developers who already have some experience with Apache OpenOffice API and with some other programming language (Java/C++/StarBasic). It is recommended that you read some background information from the developer manual before looking at the specifics of Python.
Translations
(Find here a shortened Spanish version of this document.)
Tutorial
PyUNO tutorial for Apache OpenOffice
This tutorial shows how the PyUNO bridge can be used to automate Apache OpenOffice. This is not an Apache OpenOffice tutorial, there is lots of resources available in the office development kit and the developer manual.
PyUNO Installation
Since OpenOffice.org 1.1, PyUNO is included in the default installation.
PyUNO bridge modes
PyUNO can be used in three different modes:
- Inside the Apache OpenOffice process within the scripting framework (OpenOffice.org 2.0 and later only !!)
- Inside the Python executable (and outside the Apache OpenOffice process)
Use this mode when you:
- begin to use PyUNO (as it is the more intuitive approach).
- want to trigger script execution by starting a separate process (e.g. a cgi-script within a http-server)
- want the shortest turnaround times (code - execute - code - execute ...)
Download
You can also download this documentation for off-line work.
Download pyuno-doc.zip ( less than 0.5 MB).
State
The Python-UNO bridge is feature complete, but has not been used extensively and therefore may contain some bugs. It is now integrated in the OpenOffice.org source trees. (OpenOffice.org 1.0.x is not supported.)
The documentation in its current state is targeted at developers who already have some experience with Apache OpenOffice API and with some other programming language (Java/C++/StarBasic). It is recommended that you read some background information from the developer manual before looking at the specifics of Python.
Translations
(Find here a shortened Spanish version of this document.)
Tutorial
PyUNO tutorial for Apache OpenOffice
This tutorial shows how the PyUNO bridge can be used to automate Apache OpenOffice. This is not an Apache OpenOffice tutorial, there is lots of resources available in the office development kit and the developer manual.
PyUNO Installation
Since OpenOffice.org 1.1, PyUNO is included in the default installation.
PyUNO bridge modes
PyUNO can be used in three different modes:
- Inside the Apache OpenOffice process within the scripting framework (OpenOffice.org 2.0 and later only !!)
- Inside the Python executable (and outside the Apache OpenOffice process)
Use this mode when you:
- begin to use PyUNO (as it is the more intuitive approach).
- want to trigger script execution by starting a separate process (e.g. a cgi-script within a http-server)
- want the shortest turnaround times (code - execute - code - execute ...)
'Hello World' Example
Make sure that Apache OpenOffice is not running (note that on Windows you must also terminate the Quickstarter in the systemtray at the right bottom of your desktop). Start a system shell (cmd on Win NT/2000/XP, command on Win9x, tcsh or bash on Linux/Unix). Switch to the Apache OpenOffice 'program' directory (e.g. C:Program Files (x86)OpenOffice.org 2.4program ) and start the office with the following command line parameters:
Now, use your favorite text editor to create the following 'hello_world.py' sample program:
Now, to start the above script with the Python script located in the 'program' directory:
Note: You must use the script/batch file in the 'program' directory to start Python; simply starting the Python executable in the runtime directory (or from a Python installation installed somewhere else on your machine) will not work.
This script prints 'Hello World' into the current writer document.