12 April 2014: The OpenOffice Wiki is not, and never was, affected by the heartbleed bug. Users' passwords are safe and wiki users do not need take any actions.

Python

From Apache OpenOffice Wiki
Jump to: navigation, search
OOo Extensions project

Please view the wiki usage guidelines
before contributing.

Categories:

Pages:

Extensions on the main site

Extensions in other languages:
IT - FR - ES - - JA - OC

PyUNO Logo Pyuno logo a.jpg

Python and OpenOffice

Apache OpenOffice 4 ships with the Python scripting language, version 2.7. OpenOffice.org 3.1 and above shipped with Python version 2.6.1 and older OpenOffice.org releases shipped with Python version 2.3.4. This Python distribution via OpenOffice comes with the Uno module, which connects the UNO API to the python scripting language. To run this version of Python on Linux, you can go directly to the OpenOffice PATH. And as one would expect with any distribution of Python, AOO-Python can be run from the command line as well.

If you already have a separate Python installation, you can import the uno module (the Python-UNO bridge) to it using these instructions.

If you already have a different version of Python installed on Windows, you can also access the UNO API using the COM bridge instead of the Python bridge. Requires the add-on pywin32 module so Python can talk to COM. Note that while the UNO API is uniform, the implementation by the two bridges is slightly different, so the syntax required by each is also sometimes different.

Where is the IDE ?

OpenOffice's IDE doesn't support Python, so development has to be done from another editor that does. Any volunteer for a binding is welcomed. Here is a nice blog post about using VIM a common Unix/Linux text editor configured in a way that acts like an IDE. Windows users can use Gvim and MacVim for OSX users.

Tips & Tricks

Here is some useful information about using python in AOO.

Debug output

If you launch a python script, any error will silently break the execution, making your extension hard to debug. To change this behaviour, one can change the LogLevel .

Have a look in /path/to/aoo/program/pythonscript.py and replace LogLevel.use = LogLevel.NONE with LogLevel.use = LogLevel.DEBUG .

There are also currently-undocumented environment variables that tell the pyUno bridge to log every call. Set the environment variable export PYUNO_LOGLEVEL=ARGS . The output may be a little hard to read, but helpful nonetheless.

Note that his applies only to Linux. For Windows, you need some more switches, and the output gets written to files (there is no stdout on windows :-( ).

There are still some error messages that won't appear in these logs; this will improve in the near future (cws pyunofixes4). Once the cws is integrated, I will document these switches on the official pyuno site.

Thanks to Joerg Budischewski .

Python specific information for Extension creation

To create extensions for python, it is important that you have enough familiarity with the UNO components, as well as with packaging your code for easy distribution through the OpenOffice package manager. Please check the tutorials to learn how to component-ize your code, and how to deploy remote scripting through a service implementation.

To learn to run Python on Windows, visit this link for more detailed information.

Getting Started
PYUNO Modules
  • Danny's Python Modules - Collection guide from DannyB's modules.
  • PrinttoWriter.py - This makes it easy and convenient to print a bunch of text into a Writer document.
  • Developing Calc Functions in Python - Learn how Python can be used to script your spreadsheets
  • Generating a Spreadsheet through Python - Automatically generate new spreadsheets
  • Python container components
  • PyUNOServer - The PyUNOServer is a script that works as an XML server for OpenOffice.org Calc
  • calcParser - calcParser is a small parser using the native SAX utilities within the OpenOffice.org python
  • OoConfig - OoConfig is a Python extension that seeks to provide a configuration editing facility similar to Mozilla's about:config
  • OOoRISExport.py - Exports the bibliographic database in RIS format. Also RISImport.py
  • Zotero Plugin - The Zotero plugin provides citation and bibliographic table insertion and editing functions for Writer documents.
  • OOSheet - High level python library to develop spreadsheet macros without the complexity of Uno. Focuses on spreadsheets, but may be useful for other documents.

Hacking Around

Python rules OpenOffice (by B. Bois)

Python rules OpenOffice :-)
Views
Personal tools
Navigation
Print/export
Tools