Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
lino.utils.odsreader¶
OdsReader uses odfpy to extract data from an .ods document (OpenOffice.org spreadsheet).
Thanks to Marco Conti and gtr for their blog post Read an ODS file with Python and Odfpy which was a valuable source of inspiration to me. Unlike Marco’s reader this one doesn’t store any data in memory, it just loops over the rows.
OdsReader is used to import data from .ods files into a Django database using a The Python serializer fixture, but not limited to this usage.
State : works for me, but very young and probably full of bugs.
Usage example in Lino utilities.
Functions
|
Classes
|
Like |
|
Abstract base class. |
- class lino.utils.odsreader.SimpleOdsReader(**kw)¶
Bases:
object
Abstract base class. For each .ods file you are probably creating a subclass of this.
- filename = None¶
The full path name of the .ods file to be read.
- headers = None¶
A list of unicode strings, one for each column in the file. The headers specified here must match exactly those found in the .ods file.
- cells2row(cells)¶
This will be called for each recognized data row and may perform a conversion before yielding it. Subclasses may override this.
- rows()¶
Yields the data rows found in this .ods file.
- class lino.utils.odsreader.OdsReader(**kw)¶
Bases:
SimpleOdsReader
Like
SimpleOdsReader
, but each row is converted to anlino.utils.AttrDict
. This requires you to specifiy, besides theSimpleOdsReader.headers
attrribute, another list of pure ASCII strings which must be valid Python attribute names.