Re: Python/UNO/OpenOffice?

Discussion in 'Python' started by Colin J. Williams, Oct 2, 2006.

  1. wesley chun wrote:
    > as others have said, that project provides a working interface to OOo
    > (OpenOffice 2 on Ubuntu Breezy and Dapper). i've made several posts
    > to this regard over the summer here on CLP. i was mostly using it to
    > "mess around" with documents in StarWriter.
    >
    > cheers,
    > -- wesley
    > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    > "Core Python Programming", Prentice Hall, (c)2007,2001
    > http://corepython.com
    >
    > wesley.j.chun :: wescpy-at-gmail.com
    > python training and technical consulting
    > cyberweb.consulting : silicon valley, ca
    > http://cyberwebconsulting.com

    I've done some small things with Python/OpenOffice, using Windows XP.
    They appear to work OK.

    It seems that there is only one person to maintain the Python interface
    and that there few users - no critical mass. I hope that this will
    change as OpenOffice is, with the exception of the Base component, a
    solid package. The base (database) component is evolving.

    Colin W.
     
    Colin J. Williams, Oct 2, 2006
    #1
    1. Advertising

  2. Colin J. Williams

    John Machin Guest

    Colin J. Williams wrote:

    > I've done some small things with Python/OpenOffice, using Windows XP.
    > They appear to work OK.


    As you might have noticed from my earlier post, I can't get off the
    ground. Can you please give an example (with code) of a "small thing"
    that works OK?

    TIA,
    John
     
    John Machin, Oct 2, 2006
    #2
    1. Advertising

  3. Colin J. Williams

    olive Guest

    John,

    Here is something that works for me under XPsp2 to either save a doc or
    save it as PDF:

    filepath = argv[0]
    exportpdf = argv[1]

    ctxLocal = uno.getComponentContext()
    smgrLocal = ctxLocal.ServiceManager
    resolver =
    smgrLocal.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",ctxLocal)
    url =
    "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
    ctx = resolver.resolve(url)
    smgr = ctx.ServiceManager
    desktop =
    smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)

    properties = []
    if exportpdf == "yes":
    p = PropertyValue()
    p.Name = "Hidden"
    p.Value = True
    properties.append(p)
    properties = tuple(properties)
    doc = desktop.loadComponentFromURL("file:///c:"+filepath+".odt" ,
    "_blank", 0, properties)

    if exportpdf == "yes":
    properties = []

    p = PropertyValue()
    p.Name = "Overwrite"
    p.Value = True
    properties.append(p)

    p = PropertyValue()
    p.Name = "FilterName"
    p.Value = 'writer_pdf_Export'
    properties.append(p)

    properties = tuple(properties)
    doc.storeToURL("file:///c:"+filepath+".pdf", properties)

    else:
    doc.store()

    doc.dispose()

    You must start OO this way first:
    cd C:\Program Files\OpenOffice.org 2.0\program
    soffice "-accept=socket,host=localhost,port=2002;urp;"
     
    olive, Oct 2, 2006
    #3
  4. Colin J. Williams

    olive Guest

    .... and you have to start your py file with:

    import uno, sys, socket
    from com.sun.star.beans import PropertyValue

    .... and your start_oo_server.bat file with:

    @SET PYTHONPATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program
    Files\OpenOffice.org 2.0\program\python-core-2.3.4\lib
    @SET PATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program
    Files\OpenOffice.org 2.0\program\python-core-2.3.4\bin
     
    olive, Oct 2, 2006
    #4
  5. Colin J. Williams

    John Machin Guest

    olive wrote:
    > ... and you have to start your py file with:
    >
    > import uno, sys, socket
    > from com.sun.star.beans import PropertyValue
    >
    > ... and your start_oo_server.bat file with:
    >
    > @SET PYTHONPATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program
    > Files\OpenOffice.org 2.0\program\python-core-2.3.4\lib
    > @SET PATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program
    > Files\OpenOffice.org 2.0\program\python-core-2.3.4\bin


    Many thanks for all that, olive; I made the minimal hacks to make it
    open an XLS ffile, and it worked!
    I'll try to see why that worked and my previous experiment crashed
    inside a DLL.
    Cheers,
    John
     
    John Machin, Oct 2, 2006
    #5
  6. John Machin enlightened us with:
    > Many thanks for all that, olive; I made the minimal hacks to make it
    > open an XLS ffile, and it worked!
    > I'll try to see why that worked and my previous experiment crashed
    > inside a DLL.


    Thanks, keep us posted!

    Sybren
    --
    Sybren Stüvel
    Stüvel IT - http://www.stuvel.eu/
     
    Sybren Stuvel, Oct 2, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sells, Fred

    OpenOffice UNO export PDF help needed

    Sells, Fred, Apr 30, 2006, in forum: Python
    Replies:
    1
    Views:
    745
    Michele Petrazzo
    May 1, 2006
  2. Python/UNO/OpenOffice?

    , Sep 30, 2006, in forum: Python
    Replies:
    7
    Views:
    643
    olive
    Oct 2, 2006
  3. Sells, Fred
    Replies:
    2
    Views:
    295
    Thomas Guettler
    Jan 22, 2007
  4. Nicola Larosa

    [PyCon Uno Italy] Call For Papers

    Nicola Larosa, Apr 26, 2007, in forum: Python
    Replies:
    0
    Views:
    269
    Nicola Larosa
    Apr 26, 2007
  5. Replies:
    0
    Views:
    373
Loading...

Share This Page