
createInstanceWithContext ( ".Desktop", context ) if not desktop : raise Exception, "Failed to create OpenOffice desktop on port %d " % self. sleep ( 1 ) n += 1 if not context : raise Exception, "Failed to connect to OpenOffice on port %d " % self. startup () did_start = True # Pause and try again to connect time. if n = 0 : # Exit loop if startup not desired. port ) break except NoConnectException : pass # If first connect failed then try starting OpenOffice. resolve ( "uno:socket,host=localhost,port= %d urp StarOffice.ComponentContext" % self. createInstanceWithContext ( ".UnoUrlResolver", localContext ) context = None did_start = False n = 0 while n < 6 : try : context = resolver. getComponentContext () resolver = localContext. If a connection cannot be established try to start OpenOffice. port = port def connect ( self, no_startup = False ): """ Connect to OpenOffice. """ def _init_ ( self, port = OPENOFFICE_PORT ): """ Create OORunner that connects on the specified port. insert ( 0, OPENOFFICE_LIBPATH ) break import uno from import PropertyValue from import NoConnectException class OORunner : """ Start, stop, and connect to OpenOffice. join ( OPENOFFICE_PATH, 'soffice' ) OPENOFFICE_LIBPATH = p # Add to path so we can find uno. exists ( p ): OPENOFFICE_PATH = p OPENOFFICE_BIN = os. # import sys import os import time import atexit OPENOFFICE_PORT = 8100 # Find OpenOffice.
#Openoffice linux code#
# Based on code from: # PyODConverter (Python OpenDocument Converter) v1.0.0 - # Copyright (C) 2008 Mirko Nasato # Licensed under the GNU LGPL v2.1 - or any later version. I refactored the connecting and added the ability to start This code is based on some code that I found The code also keeps track of all the copies of OpenOffice that it's Has methods for connecting to OpenOffice, for starting it, and The code consists mainly of the Python class OORunner which Runs if you use the version of Python that comes with OpenOffice. I also tested it with version 3.0 of OpenOffice but it only The code presented here was tested with version 2.5 of Python Running OpenOffice in "headless" mode means that OpenOfficeĭoesn't display a window it just waits for UNO operations (via a TCP/IP port).

How to start, stop, and connect to OpenOffice in "headless" mode. The code presented here runs outside of OpenOffice and shows UNO is specified in IDL and often the only documentation for pyuno is the UNO is an application programming language independent interface to OpenOffice. Pyuno is the Python layer that implements OpenOffice's UNO interface. Stuck at version 2.3 for quite a while now. The version of Python that's embedded in OpenOffice has been If you want to get started with pyuno be prepared for an oftenįrustrating experience: the documentation is sketchy Pyuno allows you to create macros inside OpenOffice and it also allows you to createĮxternal Python scripts that talk to a running copy of OpenOffice.
