Read / Write OpenOffice SpreadSheet ?

T

Torsten Mohr

Hi,

i search for a possibility to access OpenOffoce SpreadSheets from Python
with a reasonably new version of Python.

Can anybody point me to a package that can do this?


Best regards,
Torsten.
 
T

Tim Harig

i search for a possibility to access OpenOffoce SpreadSheets from Python
with a reasonably new version of Python.

Can anybody point me to a package that can do this?

There is no package needed to read or write the new open document files.
The files are merely a jar archive containing XML files. You can open
and update them using jar as a subprocess and manipulate the XML files
using your favorite XML libraries DOM/SAX/XPath/Etree/etc.

If that doesn't suit you, you can manipulate them using Oo_Org through its
UNO interface; but, I find that much more involved then simply accessing
the files directly.
 
J

joymanchen

"Torsten Mohr" 写入消æ¯
Hi,

i search for a possibility to access OpenOffoce SpreadSheets from Python
with a reasonably new version of Python.

Can anybody point me to a package that can do this?


Best regards,
Torsten.


--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---
 
T

Torsten Mohr

Hello,
There is no package needed to read or write the new open document files.
The files are merely a jar archive containing XML files. You can open
and update them using jar as a subprocess and manipulate the XML files
using your favorite XML libraries DOM/SAX/XPath/Etree/etc.

thanks for your hint. I was aware of that, OO files are a bunch of zipped
XML files. But, i searh for something more comfortable/highlevel that lets
me just do things like doc.Cell(1, 3) = 'abc' or so.
If that doesn't suit you, you can manipulate them using Oo_Org through its
UNO interface; but, I find that much more involved then simply accessing
the files directly.

Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and
i'd like to base on something actual.


Best regards,
Torsten.
 
A

Adam Tauno Williams

Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and
i'd like to base on something actual.

I do not *believe* this is true.

<http://pypi.python.org/pypi/cloudooo/1.0.9> for instance is Python 2.6
and uses PyUNO.

I would strongly recommend against floundering about in OOo's very
complex XML files - it is trivially easy to render a document unusable.
 
S

Stefan Behnel

Adam Tauno Williams, 17.12.2010 17:02:
I do not *believe* this is true.

<http://pypi.python.org/pypi/cloudooo/1.0.9> for instance is Python 2.6
and uses PyUNO.

The Python installation can be replaced. Last I heard, many Linux distros
used the platform Python, for example, instead of shipping an embedded one
with OOo.

I would strongly recommend against floundering about in OOo's very
complex XML files - it is trivially easy to render a document unusable.

True. It's not so much of a problem to read them, but writing a correct
document can be tricky. What works relatively well is to write a template
document in OOo and do programmatic replacements in it. But that's not
guaranteed to work, either.

Stefan
 
T

Tim Harig

I would strongly recommend against floundering about in OOo's very
complex XML files - it is trivially easy to render a document unusable.

I do it all the time and have never had a problem. I don't generate the
documents from scratch; I generate a template that contains everything
that don't need to dynamically generate. Then I use one of two methods
to to update the content.xml:

1. In the simplest cases, I only need to change a single data field. I
replace the literal data in the content.xml file with:

<replace field="variable_name"/>

Then, using a DOM implementation, I can use getElementsByTagName()
to get all of the replace tags and send the variable name to a
distpach that generates the text used to replace the tag.

2. For collections of data (spreadsheet cells, table cells/rows, etc,
I leave one piece of sample data in place. I then clone the DOM
element that I can use as a template and delete the origional.
Entering the data is then a simple matter of cloning the template
element, updating the information that it contains, and adding
it to the childNodes of the parent. Since tags all come from
the file that Oo_Org/LibreOffice generated, the resulting markup
will be valid.

Once the content.xml file has been updated, I simply run jar as a
subprocess to update the content.xml file in the ods/odt file.
 

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

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,448
Latest member
DeanaQ4445

Latest Threads

Top