modifying open office spreadsheet (with OO installed)

N

News123

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
 
N

News123

Mumbling to myself, perhaps somebody else is interested.
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)
 
J

Jim Byrnes

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

Yes I am.
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top