modifying open office spreadsheet (with OO installed)

Discussion in 'Python' started by News123, Apr 28, 2010.

  1. News123

    News123 Guest

    Hi,


    I wanted to know who can recommend a good module/library, that allows to
    modify an Open Office spreadsheet.

    One can assume, that Open Office is installed on the host.




    Is PyUNO_bridge ( http://wiki.services.openoffice.org/wiki/PyUNO_bridge
    ) the way to go or is there something better / faster / newer.

    Are there any good wrapper / abstraction libraries.



    Ideally I'd like to have a solution, that works with python 2.6 and on
    windows and linux.


    My initial tasks would be rather simple:
    searching for rows with a certain name in a column and insert a value in
    a neighbour column.

    Lateron I would be interested in
    - inserting / deleting rows /columns
    - copying cells.
    - inserting formulas
    - running existing macros
    - printing interactively
    but this can wait a little.


    thanks for any hints or sharing your experience



    N
    News123, Apr 28, 2010
    #1
    1. Advertising

  2. News123

    News123 Guest

    Mumbling to myself, perhaps somebody else is interested.

    News123 wrote:
    > Hi,
    >
    >
    > I wanted to know who can recommend a good module/library, that allows to
    > modify an Open Office spreadsheet.
    >
    > One can assume, that Open Office is installed on the host.
    >
    >

    Following url gives a small introduction about using the PyUno-bridge to
    open-read-modify-save a spread sheet
    http://stuvel.eu/ooo-python




    A simple sample code snippet could look like:
    ( Danny.OOo_OOoLib from above url )

    import os
    import uno
    import unohelper
    import Danny.OOo_OOoLib as OOoLib

    #must start open office with
    #soffice "-accept=socket,host=localhost,port=8100;urp;"
    fname = "tst.ods"
    new_fname = "tstnew.ods"
    url = unohelper.systemPathToFileUrl(
    os.path.abspath(fname))
    desktop = OOoLib.getDesktop()
    doc = desktop.loadComponentFromURL(
    url, "_blank", 0, () )

    sheet = doc.getSheets().getByIndex(0)
    cell = sheet.getCellByPosition(0,0)
    text_value = cell.getFormula()
    if text_value > 3:
    new_val = "was greater three"
    else:
    new_val = "was not greater three"
    celltochange = sheet.getCellByPosition(1,0)
    celltochange.setFormula(new_val)
    url = unohelper.systemPathToFileUrl(
    os.path.abspath(new_fname))
    doc.storeToURL(url, ())
    doc.close(True)
    News123, Apr 29, 2010
    #2
    1. Advertising

  3. News123

    Jim Byrnes Guest

    News123 wrote:
    > Mumbling to myself, perhaps somebody else is interested.


    Yes I am.

    > News123 wrote:
    >> Hi,
    >>
    >>
    >> I wanted to know who can recommend a good module/library, that allows to
    >> modify an Open Office spreadsheet.
    >>
    >> One can assume, that Open Office is installed on the host.
    >>
    >>

    > Following url gives a small introduction about using the PyUno-bridge to
    > open-read-modify-save a spread sheet
    > http://stuvel.eu/ooo-python
    >
    >
    >
    >
    > A simple sample code snippet could look like:
    > ( Danny.OOo_OOoLib from above url )
    >
    > import os
    > import uno
    > import unohelper
    > import Danny.OOo_OOoLib as OOoLib
    >
    > #must start open office with
    > #soffice "-accept=socket,host=localhost,port=8100;urp;"
    > fname = "tst.ods"
    > new_fname = "tstnew.ods"
    > url = unohelper.systemPathToFileUrl(
    > os.path.abspath(fname))
    > desktop = OOoLib.getDesktop()
    > doc = desktop.loadComponentFromURL(
    > url, "_blank", 0, () )
    >
    > sheet = doc.getSheets().getByIndex(0)
    > cell = sheet.getCellByPosition(0,0)
    > text_value = cell.getFormula()
    > if text_value> 3:
    > new_val = "was greater three"
    > else:
    > new_val = "was not greater three"
    > celltochange = sheet.getCellByPosition(1,0)
    > celltochange.setFormula(new_val)
    > url = unohelper.systemPathToFileUrl(
    > os.path.abspath(new_fname))
    > doc.storeToURL(url, ())
    > doc.close(True)
    >


    I am teaching myself Python because I like to script spreadsheets. Up
    until now I was unable to find any entry level info on using Python with
    OO. Thanks for posting this link.

    Regards, JIm
    Jim Byrnes, Apr 29, 2010
    #3
  4. Jim Byrnes wrote:
    > News123 wrote:
    >> Mumbling to myself, perhaps somebody else is interested.

    >
    > Yes I am.
    >
    >> News123 wrote:
    >>> Hi,
    >>>
    >>>
    >>> I wanted to know who can recommend a good module/library, that allows to
    >>> modify an Open Office spreadsheet.
    >>>
    >>> One can assume, that Open Office is installed on the host.
    >>>
    >>>

    >> Following url gives a small introduction about using the PyUno-bridge to
    >> open-read-modify-save a spread sheet
    >> http://stuvel.eu/ooo-python


    If .xls files are an option for you, xlutils.copy is your friend:

    https://secure.simplistix.co.uk/svn/xlutils/trunk/xlutils/docs/copy.txt

    cheers,

    Chris
    Chris Withers, May 4, 2010
    #4
  5. News123

    News123 Guest

    Hi CHris,


    Chris Withers wrote:
    > Jim Byrnes wrote:
    >> News123 wrote:
    >>> Mumbling to myself, perhaps somebody else is interested.

    >>
    >> Yes I am.
    >>
    >>> News123 wrote:
    >>>> Hi,
    >>>>
    >>>>
    >>>> I wanted to know who can recommend a good module/library, that
    >>>> allows to
    >>>> modify an Open Office spreadsheet.
    >>>>
    >>>> One can assume, that Open Office is installed on the host.
    >>>>
    >>>>
    >>> Following url gives a small introduction about using the PyUno-bridge to
    >>> open-read-modify-save a spread sheet
    >>> http://stuvel.eu/ooo-python

    >
    > If .xls files are an option for you, xlutils.copy is your friend:
    >
    > https://secure.simplistix.co.uk/svn/xlutils/trunk/xlutils/docs/copy.txt
    >


    In fact I like this library and for some things I intend to do it's a
    rather nice option.

    However for changing a few fields and keeping all the rest exactly as it
    is it doesn't seem to be the most apropriate solution (without some hacking)
    as formulas might get lost.


    > cheers,
    >
    > Chris
    >
    News123, May 6, 2010
    #5
    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. Stan Accrington
    Replies:
    1
    Views:
    917
    Michael Borgwardt
    May 13, 2004
  2. hackingKK
    Replies:
    0
    Views:
    273
    hackingKK
    Mar 16, 2010
  3. News123
    Replies:
    0
    Views:
    277
    News123
    Apr 28, 2010
  4. Ed Keith
    Replies:
    2
    Views:
    337
    John Machin
    Dec 22, 2010
  5. Greg Cyrus

    Zoom the Spreadsheet OWC11 Office Web Components

    Greg Cyrus, Dec 12, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    171
    Greg Cyrus
    Dec 12, 2006
Loading...

Share This Page