modifying open office spreadsheet (with OO installed)

Jim Byrnes jf_byrnes at comcast.net
Thu Apr 29 23:33:39 CEST 2010


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






More information about the Python-list mailing list