Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Read / Write OpenOffice SpreadSheet ? (http://www.velocityreviews.com/forums/t740283-read-write-openoffice-spreadsheet.html)

Torsten Mohr 12-17-2010 01:07 AM

Read / Write OpenOffice SpreadSheet ?
 
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.


Tim Harig 12-17-2010 01:53 AM

Re: Read / Write OpenOffice SpreadSheet ?
 
On 2010-12-17, Torsten Mohr <tmohr@s.netic.de> wrote:
> 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.

joymanchen 12-17-2010 02:46 AM

Re: Read / Write OpenOffice SpreadSheet ?
 


"Torsten Mohr" 写入消息 news:ieed6o$iqd$1@news.LF.net...

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: news@netfront.net ---

Torsten Mohr 12-17-2010 09:19 AM

Re: Read / Write OpenOffice SpreadSheet ?
 
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.


Stefan Behnel 12-17-2010 03:48 PM

Re: Read / Write OpenOffice SpreadSheet ?
 
Torsten Mohr, 17.12.2010 02:07:
> 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?


Have you looked through the relevant PyPI packages?

http://pypi.python.org/pypi?%3Aactio...erm=openoffice

Stefan


Adam Tauno Williams 12-17-2010 04:02 PM

PyUNO [Was: Read / Write OpenOffice SpreadSheet ?]
 
On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote:
> 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.


Stefan Behnel 12-17-2010 04:35 PM

Re: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?]
 
Adam Tauno Williams, 17.12.2010 17:02:
> On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote:
>> 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.


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


Tim Harig 12-17-2010 06:31 PM

Re: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?]
 
On 2010-12-17, Adam Tauno Williams <awilliam@whitemice.org> wrote:
> 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.

Stef Mientki 12-17-2010 07:02 PM

Re: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?]
 
On 17-12-2010 17:02, Adam Tauno Williams wrote:
> On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote:
>> 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.
>

looks great,
but is there something alike for Windows ?

thanks,
Stef Mientki

Terry Reedy 12-17-2010 11:56 PM

Re: Read / Write OpenOffice SpreadSheet ?
 
On 12/17/2010 4:19 AM, Torsten Mohr wrote:
> 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.


http://opendocumentfellowship.com/projects/odfpy

--
Terry Jan Reedy



All times are GMT. The time now is 02:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.