Hello everyboby,

I'm trying to create an .odt document just using python, and the API uno (available with the standard distribution of Apache Open Office). But, I'm completely stuck for the moment, and this main goal seems to be still a long way to go...

For information, I'm using a mac os x 10.9.5 computer, and my Apacha Open Office version is the 4.1.1


Let me explain what I have done, and where I'm currently stuck:


  • First of all, I've opened a terminal to launch OpenOffice, with the following:
    First of all, I've opened a terminal to launch OpenOffice, with the following:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $ cd ../../Applications/OpenOffice.app/Contents/MacOS/
    $ ./soffice.bin -headless -nofirststartwizard -accept="uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"
    I have to confess that I've found this on the web and do not really understand what the second line is doing... Probably, it's because I do not know what the file soffice.bin contains... For me, it opens a socket in order to communicate with OpenOffice. Am I write? If you can explain me precisely this, I would be wonderful actually!


  • Secondly, I open an other terminal, go in the same folder than in the first terminal, then launch python, import the uno package and declare a class whose goal is to create OpenOffice easily. Here is the code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    $ cd ../../Applications/OpenOffice.app/Contents/MacOS/
    $ python
    >>> import uno
    >>> class UnoClient:
    ...    def __init__(self):
    ...        localContext = uno.getComponentContext()
    ...        resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
    ...        self.smgr = resolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager")
    ...    def create_document(self, app):
    ...        remoteContext = self.smgr.getPropertyValue("DefaultContext")
    ...        desktop = self.smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)
    ...        url = "private:factory/{0}".format(app)
    ...        return desktop.loadComponentFromURL(url,"_blank", 0, () )
    Once again, I don't understand all the detail of this code and would not have been able to code it myself...I think that it's like a client, the other terminal being the server. The line "self.smgr = ..." should be here to try to "connect" to the "server socket", or something like that...


  • Finally, I'm trying to declare a UnoClient objet by
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    unoClient = UnoClient()
    Of course, it would have been too simple if this code would have be correct... Python answer me
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 6, in __init__
    __main__.NoConnectException: Connector : couldn't connect to socket (Undefined error: 0)



Does anyone has some ideas, advices or references to understand what I am doing?

Thanks very much for all your answer,

Tolliob