[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Im-/Export of ODF files?
- From: Yuri Takhteyev <yuri@...>
- Date: Mon, 26 Jan 2009 11:02:14 -0800
> Has anyone looked at importing and/or exporting ODF (open document format,
> e.g. used by open office) files using lua? I am mainly interested in
> writing and reading spreadsheet tables. Using CSV files is not sufficient
> for my purposes.
I've done both in Python and tried doing the same in Lua last year.
It's fairly straightforward, though I didn't have time to finish and
ended up going to a python script that I already had working.
1. Unzip the odf document as if it was a zip file. There are a few lua
libraries that can do this for you.
2. Open "content.xml" in the archive. This is an XML file. It's has no
whitespace and is hard to read as is, but if you open it in a good XML
editor that can apply indentation, then the file is very easy to
understand. You don't need to read ODF specs - just read the XML file
from an existing document. You will see something like this:
<table:table table:name="Sheet1" ...>
<table:table-cell table:formula="oooc:=SUM([.B2:.B4])" ...>
Use your favorite Lua XML parsing tool
(http://lua-users.org/wiki/LuaXml) to parse this.
I always use an existing ODF document as a template. I keep it
unzipped in a directory and when I need a new ODF document, I generate
a new content.xml and zip up the directory.
I use cosmo (http://cosmo.luaforge.net) for generating content.xml.
Email me if you want an example of a somewhat unrefined Lua script
that uses cosmo to generate content.xml for an ODT file.