Using Python on Windows

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

Please view the wiki usage guidelines
before contributing.



Extensions on the main site

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

Introduction to Python on Apache OpenOffice

You need Apache OpenOffice installed with its Python-UNO bridge.

If you do not customize the installation, Python-UNO bridge is installed as default on recent version. Install Apache OpenOffice. If you are installing it for the first time, then be sure to do a Custom install and install the Python-UNO bridge under Optional Components.

If you already have Apache OpenOffice installed, then go into your Apache OpenOffice folder and run Setup. Pick Modify, click Next. Under Optional Components, be sure to install the Python-UNO bridge.

In order to use the python-uno bridge, the python code must run from the Python that comes with Apache OpenOffice. There is apparently some issue with the standard C library. The Python 2.2.2 that comes with Apache OpenOffice has been compiled using the StdCLib that Apache OpenOffice uses rather than the one that python would normally be compiled with.

If you want an interactive Python command shell right now, go into your Apache OpenOffice\program subfolder and run the batch file named python.bat. You get a python shell. You can then use the statement Code:

   import uno

You can now connect to any Apache OpenOffice that will accept a remote UNO connection.

I suppose that leads us to the next issue… Configuring Apache OpenOffice to listen for UNO connections.

It is also possible to write a component in Python and install it into the office. It is my understanding (but I have not tried yet) that when you do this you do NOT need to configure Apache OpenOffice to listen for uno connections.

Therefore, the two ways to use Python are...

  • Outside of Apache OpenOffice -- with a remote uno connection.
  • Inside of Apache OpenOffice -- as an installed component.

Approach 1 is the quick and easy way to write and debug code.

Approach 2 is a great way to _deliver_ finished code to a user.

See this for more information about the Python-UNO bridge in Apache OpenOffice.

Configuring Apache OpenOffice to listen for UNO connections

If you write programs in Java or Python and run them external to Apache OpenOffice, then you need to configure Apache OpenOffice to listen for a uno connection.

It is possible to run your program on computer A, and connect to computer B which is running Apache OpenOffice, and have your program at A manipulate the Apache OpenOffice running on B. In fact, A and B can even be running different operating systems. I have done this personally using Java. With Python, I have only run my program on the same computer as Apache OpenOffice -- but it should work the same way.

In the past, it was necessary to either

  • launch Apache OpenOffice with a special parameter to make it listen
  • hand edit one of Apache OpenOffice's configuration files

Both of the above options I explained here previously.

You can hand edit an XML file for version 1.0 of, or an XCU file for version 1.1 of

Later, I developed a macro to do this editing and announced it here.

My UnoConnectionListener document can be obtained from Macros on Sourceforge.

Just download the document. Open it. Configure text boxes to taste. (Read the text of the above post if necessary.) Then click a button. Quit Apache OpenOffice. Re-launch Apache OpenOffice and it should henceforth (until you reconfigure it again) always listen for Uno connections. You can configure it to listen to connections only from localhost, or from any other computer.

Personal tools