Python & OpenOffice Spreadsheets

Discussion in 'Python' started by Gerhard Häring, Nov 23, 2009.

  1. Is there a *simple* way to read OpenOffice spreadsheets?

    Bonus: write them, too?

    I mean something like:

    doc.cells[0][0] = "foo"
    doc.save("xyz.ods")

    >From a quick look, pyodf offers little more than just using a XML parser

    directly.

    -- Gerhard
     
    Gerhard Häring, Nov 23, 2009
    #1
    1. Advertising

  2. Gerhard Häring

    Paul Rudin Guest

    Gerhard Häring <> writes:

    > Is there a *simple* way to read OpenOffice spreadsheets?
    >
    > Bonus: write them, too?
    >
    > I mean something like:
    >
    > doc.cells[0][0] = "foo"
    > doc.save("xyz.ods")
    >
    >>From a quick look, pyodf offers little more than just using a XML parser

    > directly.



    Depends on exactly what you mean by "simple" - but pyuno allows you to
    read and write openoffice spreadsheets.
     
    Paul Rudin, Nov 23, 2009
    #2
    1. Advertising

  3. Gerhard Häring

    Terry Reedy Guest

    Krishnakant wrote:
    > On Mon, 2009-11-23 at 11:12 +0000, Paul Rudin wrote:
    >> Gerhard Häring <> writes:
    >>
    >>> Is there a *simple* way to read OpenOffice spreadsheets?
    >>>
    >>> Bonus: write them, too?
    >>>
    >>> I mean something like:
    >>>
    >>> doc.cells[0][0] = "foo"
    >>> doc.save("xyz.ods")
    >>>
    >>> >From a quick look, pyodf offers little more than just using a XML parser
    >>> directly.

    >>
    >> Depends on exactly what you mean by "simple" - but pyuno allows you to
    >> read and write openoffice spreadsheets.

    >
    >
    > Odfpy is a good module and is easy too.


    Tarball at
    http://pypi.python.org/pypi/odfpy/

    Hello world example at
    http://opendocumentfellowship.com/development/projects/odfpy
     
    Terry Reedy, Nov 23, 2009
    #3
  4. Gerhard Häring

    r Guest

    On Nov 23, 4:49 am, Gerhard Häring <> wrote:
    > Is there a *simple* way to read OpenOffice spreadsheets?
    >
    > Bonus: write them, too?
    >
    > I mean something like:
    >
    > doc.cells[0][0] = "foo"
    > doc.save("xyz.ods")
    >
    > >From a quick look, pyodf offers little more than just using a XML parser



    I find the syntax far to complicated than it should be. Here is an
    example just to insert some text..

    import uno

    """ Here is the sequence of things the lines do:
    1. Get the uno component context from the PyUNO runtime
    2. Create the UnoUrlResolver
    3. Get the central desktop object
    4. Declare the ServiceManager
    5. Get the central desktop object
    6. Access the current writer document
    7. Access the document's text property
    8. Create a cursor
    9. Insert the text into the document """

    localContext = uno.getComponentContext()
    resolver = localContext.ServiceManager.createInstanceWithContext(
    "com.sun.star.bridge.UnoUrlResolver", localContext )
    ctx = resolver.resolve
    ( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext
    ( "com.sun.star.frame.Desktop",ctx)
    model = desktop.getCurrentComponent()
    text = model.Text
    cursor = text.createTextCursor()

    text.insertString( cursor, "Hello World", 0 )

    """ Do a nasty thing before exiting the python process. In case the
    last call is a one-way call (e.g. see idl-spec of insertString),
    it must be forced out of the remote-bridge caches before python
    exits the process. Otherwise, the one-way call may or may not reach
    the target object.
    I do this here by calling a cheap synchronous call
    (getPropertyValue)."""
    ctx.ServiceManager

    WHAT!?!?!??!

    I don't mean to discredit these guys but the API should be re-thought,
    and re-written! I don't care about component contexts, unoresolvers,
    or little green aliens. I just want to insert 'Hello World' into cell
    A3! Sheesh, There must be an easier way!
     
    r, Nov 24, 2009
    #4
  5. On Nov 23, 5:49 am, Gerhard Häring <> wrote:
    > Is there a *simple* way to read OpenOffice spreadsheets?
    >
    > Bonus: write them, too?
    >
    > I mean something like:
    >
    > doc.cells[0][0] = "foo"
    > doc.save("xyz.ods")
    >
    > >From a quick look, pyodf offers little more than just using a XML parser

    >
    > directly.
    >
    > -- Gerhard



    OO Calc has an HTML file feature for auto updating fields in a
    spreadsheet.

    I hacked together something for a talk a few years ago:

    http://www.icanprogram.com/hosug

    (See Open Office Calc demo section)
    While it isn't Python code it should be easy enough to convert to
    Python.

    bob
     
    bobicanprogram, Nov 25, 2009
    #5
  6. In message <486869af-d89f-4261-b4c2-
    >, r wrote:

    > I find the syntax far to[o] complicated than it should be.


    That’s because it was originally written for Java programmers.
     
    Lawrence D'Oliveiro, Nov 28, 2009
    #6
  7. Gerhard Häring

    r Guest

    On Nov 27, 10:44 pm, Lawrence D'Oliveiro <l...@geek-
    central.gen.new_zealand> wrote:
    > In message <486869af-d89f-4261-b4c2-
    >
    > >, r wrote:
    > > I find the syntax far to[o] complicated than it should be.

    >
    > That’s because it was originally written for Java programmers.


    Well that explains the high level of asininity alright! ;-)
     
    r, Nov 28, 2009
    #7
  8. Gerhard Häring

    Paul Rudin Guest

    r <> writes:

    > On Nov 23, 4:49 am, Gerhard Häring <> wrote:
    >> Is there a *simple* way to read OpenOffice spreadsheets?
    >>
    >> Bonus: write them, too?
    >>
    >> I mean something like:
    >>
    >> doc.cells[0][0] = "foo"
    >> doc.save("xyz.ods")
    >>
    >> >From a quick look, pyodf offers little more than just using a XML parser

    >
    >
    > I find the syntax far to complicated than it should be. Here is an
    > example just to insert some text..


    [employing weapons of mass snippage]

    It's true that it's a hassle, but the boiler plate stuff can be stuck in
    a function and then forgotton about really.
     
    Paul Rudin, Nov 28, 2009
    #8
    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. Raoul Snyman
    Replies:
    14
    Views:
    11,141
    Curt_C [MVP]
    Apr 29, 2004
  2. John Machin
    Replies:
    15
    Views:
    772
  3. Jonathan Hunt

    Python library for reading ODF Spreadsheets

    Jonathan Hunt, Dec 3, 2006, in forum: Python
    Replies:
    2
    Views:
    365
  4. spirit
    Replies:
    4
    Views:
    564
    spirit
    Aug 3, 2007
  5. markolopa
    Replies:
    5
    Views:
    398
Loading...

Share This Page