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.
The following code reads a file odsreader_sample.ods and prints a line of text for each row of data.
>>> class Sample(OdsReader): ... filename = srcpath('odsreader_sample.ods') ... headers = ["N°", "Prénom", "Last name", "Country", "City", "Language"] ... column_names = 'no first_name last_name country city language'.split() ... >>> for row in Sample().rows(): ... print( "%(first_name)s %(last_name)s from %(city)s" % row) Rudi Rutté from Eupen Romain Raffault from Liège Rando Roosi from Tallinn Rik Rozenbos from Antwerpen Robin Rood from London
(Note: these are fictive person names from
(This module's source code is available here.)
Abstract base class.
Abstract base class. For each .ods file you are probably creating a subclass of this.
The full path name of the .ods file to be read.
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.
This will be called for each recognized data row and may perform a conversion before yielding it. Subclasses may override this.
Yields the data rows found in this .ods file.
SimpleOdsReader, but each row is converted to an
lino.utils.AttrDict. This requires you to specifiy, besides the
SimpleOdsReader.headersattrribute, another list of pure ASCII strings which must be valid Python attribute names.