lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> 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.

For reading:

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-column .../>
   <table:table-row table:style-name="ro1"...>
    <table:table-cell office:value-type="string"...>
    <table:table-cell table:formula="oooc:=SUM([.B2:.B4])" ...>

Use your favorite Lua XML parsing tool
( to parse this.

For exporting:

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 ( 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.

  - yuri