Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- opendocument -> csv filter ?
September 20, 2006, 2:28 pm
rate this thread
there is an openoffice perl module by Jean-Marie Gourne, but I have
never managed to figure out how to get this module to properly extract
spreadsheet data into simple csv files. (I know it needs a
decompression of repeated elements, but I could not pass it the right
parameters to make it stop complain.) has anyone written a sample
program that does this? a sample would be highly appreciated.
Re: opendocument -> csv filter ?
There is a getTableText() method in the package; it directly exports the
content of a table as flat text, with parametrizable field/record
separators (the default separators are ";" and "\n"). It may be convenient
for simple CSV extractions. This method works with spreadsheets as well as
with tables included in text documents. Caution: in spreadsheets,
getTableText(), like any other table-related method, should be used on
previously noormalized tables (look at the normalizeSheet() and getTable()
entries in the manual).
The following example opens a spreadsheet, selects a sheet by name in a
document, then exports is as CSV:
# get a read/write handle to the content
my $doc = ooDocument(file => "mydata.ods", member => "content");
# normalize a 80x30 area in the
my $table = $doc->getTable("Sheet1", 80, 30);
# exports the content
The CSV separators could be setting the appropriate variables in the
field_separator and line_separator instance variables of the document
handler. For example:
$doc-> = ',';
will force any subsequent getTableText() to use the comma instead of the
semicolon as CSV field terminator. The field_ and line_separator variables
cas accept any arbitrary string, so they could be used to create custom,
Other methods, such as getCellValue(), could be used in order to build more
specific table export applications on a cell by cell basis.
All the table-related stuff of the API is described in the
OpenOffice::OODoc::Text manual chapter