Re: Reading OpenOffice spreadsheet in Python?

2014-05-21 Thread dieter
Skip Montanaro s...@pobox.com writes:
 ...
 That then puts me in the market for an xlrd
 replacement. Is there something akin to xlrd for OpenDocument
 spreadsheets?

Unlike the binary excel format (at least for early versions),
OpenDocument is a well documented
file format (a zip file containing various XML files; processible
by standard XML tools). Thus, you may get at the content
via zipfile and Python's xml tools.

It might be possible to create an xlrd replacement based
on zipfile and the xml package -- but, of course, one
would need to study the (complex) description for the involved
XML files.

In the Plone world, there are text extractors/html converters
for OpenDocument which go this route. I do not know how
well they work.




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-21 Thread Rustom Mody
On Tuesday, May 20, 2014 10:08:06 PM UTC+5:30, Skip Montanaro wrote:
 I don't have Windows and since upgrading my Mac to Mavericks I no
 longer have Excel of any flavor. I have a few Excel spreadsheets in
 which I store parameters from which I generate other config files. I
 read those spreadsheets using xlrd.

 I am so fed up with LibreOffice's inability to properly support really
 basic Excel capabilities, I'm about ready to throw my computer out the
 window.

Another possibility: Use google drive/docs spreadsheet capability.
Makes much less mess than libreoffice and will export to standard formats
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-21 Thread Skip Montanaro
On Wed, May 21, 2014 at 3:53 AM, Rustom Mody rustompm...@gmail.com wrote:
 Another possibility: Use google drive/docs spreadsheet capability.
 Makes much less mess than libreoffice and will export to standard formats

Correct, though it separates my spreadsheet from the Git repository,
and means anyone else at work who might work on this stuff would need
to be granted access. Not insurmountable problems, but not great
either.

I tried Gnumeric today. The first edits caused no problems. Knock on wood...

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-20 Thread Chris Angelico
On Wed, May 21, 2014 at 2:38 AM, Skip Montanaro s...@pobox.com wrote:
 Before someone suggests
 config parser/Windows INI files... A spreadsheet format is kinda handy
 in this case because I do use a few formulas to define some of the
 parameters. Adding a new row (new config file) or column (new
 parameter) is a breeze.

Okay, I won't suggest Windows INI files, but I'll still suggest taking
a step back and figuring out exactly what you're trying to accomplish.
Can you separate out the real data from the formula-derived info, put
the former into a git-managed file, and the latter into something you
regenerate by script (maybe off a makefile)? Organize your source file
in such a way that adding a new config file or new parameter is easy.
The beauty of a spreadsheet is that a cell could be *either* a formula
*or* actual data, completely indistinguishably (note, some may argue
that this is also a major weakness of spreadsheets); I would guess you
most likely don't need that flexibility, and can easily separate
source and calculated. You could make your file format CSV or tab
delimited, and then use LibreOffice to edit it, if that makes the most
sense.

Something to consider, since I can't specifically advise on OO/LO
readers/writers. :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-20 Thread Martin Manns
On Tue, 20 May 2014 11:38:06 -0500
Skip Montanaro s...@pobox.com wrote:

 I am so fed up with LibreOffice's inability to properly support really
 basic Excel capabilities, I'm about ready to throw my computer out the

Could you please give some examples, what basic Excel capabilities you
are missing?

 I'm open to other options as well. I see a number of Google
 spreadsheet modules, and there is pyspread. The former has the
 permission issue (besides, where I work everything goes into Git), and
 I'm not sure how full-featured or stable the latter is (but, will
 investigate).

Maybe gnumeric may be an option, too.

Pyspread should run fine on the Mac. However, Macs are not officially
supported because there are no testers for OSX, yet.

Please note that pyspread does not translate Excel xls files into
Python but only imports cell contents and formatting via xlrd. If you
use Excel cell functions or VBA then you would have to migrate your
code to Python.


Martin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-20 Thread Skip Montanaro
On Tue, May 20, 2014 at 2:45 PM, Martin Manns mma...@gmx.net wrote:
 I am so fed up with LibreOffice's inability to properly support really
 basic Excel capabilities, I'm about ready to throw my computer out the

 Could you please give some examples, what basic Excel capabilities you
 are missing?

That's the problem. It's not that it's obviously missing some
features. It's that the files it writes sometimes are misinterpreted
by xlrd. (Maybe the problem is xlrd, but it never has a problem with
actual Excel-generated XLS files.)

For example, I use a formula to generate a sequence of strings in one column:

F0, G0, H0, ..., Z0, F1, G1, ...

continuing for as long as I have data in an adjoining column. If I add
or delete rows, this sequence grows and shrinks. It looks fine in the
spreadsheet. I rarely, if ever, change the number of rows, so the
values in this column rarely, if ever, change. Still, sometimes when
xlrd reads the values out of that column it finds all cells in that
column contain the number 0. If I mess around with the spreadsheet in
ways which are apparently unrelated to this column, I can sometimes
get it to read right, sort of like hitting a jukebox to stop a record
from skipping.

I haven't tried changing the output format to XLSX format (isn't that
a compressed XML document?), but maybe I should give that a whirl. I
don't know if xlrd will read such files (at first blush, it appears
not).

Also, Mac isn't my primary platform. This problem occurs using the
Linux version of LibreOffice as well. Sometimes I edit this
spreadsheet from home though. Before I upgraded to OS X Mavericks, I
still had an ancient version of Excel for Mac which worked fine
(despite all the disparaging remarks I've seen over the years about
that product). Once I upgraded though, that was no longer an option.

Thanks for the gnumeric and pyspread suggestions. I thought gnumeric
was a long dead project, but see that it's available for my Mac, so
I'll try that right off. I'll also play around with pyspread and see
how that does. I don't mind rewriting my couple of formulas, though I
will no longer be able to rely on the Excel experts at work. :-)

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-20 Thread Skip Montanaro
On Tue, May 20, 2014 at 11:49 AM, Chris Angelico ros...@gmail.com wrote:
 Okay, I won't suggest Windows INI files, but I'll still suggest taking
 a step back and figuring out exactly what you're trying to accomplish.
 Can you separate out the real data from the formula-derived info, put
 the former into a git-managed file, and the latter into something you
 regenerate by script (maybe off a makefile)?

Actually, I'm sympathetic to INI files. I like the simplicity. The
ultimate config files are output in XML though (ugh). Somewhere along
the way, I want to avoid typing repetitive information into files.
Today, I use a template file, read the spreadsheet with xlrd and
generate the XML cruft with Cheetah. I could retain Excel (or Open
Document or pyspread or some other spreadsheet) and then export to CSV
files. That would solve the issue as well. Though it would be an extra
step I'd have to do manually (because I can rely on xlrd), it would
still leave me with the input-to-config-file data in tabular form.

I'll figure something out. Something else that occurs to me as I write
this is that Excel files tend to acquire all sorts of cruft, right? Or
is that just Word files? Perhaps I can make things better by
copying/pasting the existing spreadsheet data into a fresh spreadsheet
that hasn't been updated repeatedly?

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-20 Thread Rustom Mody
On Tuesday, May 20, 2014 10:08:06 PM UTC+5:30, Skip Montanaro wrote:
 I don't have Windows and since upgrading my Mac to Mavericks I no
 longer have Excel of any flavor. I have a few Excel spreadsheets in
 which I store parameters from which I generate other config files. I
 read those spreadsheets using xlrd.

 I am so fed up with LibreOffice's inability to properly support really
 basic Excel capabilities, I'm about ready to throw my computer out the
 window. So, I'm looking for alternatives. Before someone suggests
 config parser/Windows INI files... A spreadsheet format is kinda handy
 in this case because I do use a few formulas to define some of the
 parameters. Adding a new row (new config file) or column (new
 parameter) is a breeze. 

Are you familiar with emacs' org mode tables?

http://orgmode.org/org.html#Tables

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading OpenOffice spreadsheet in Python?

2014-05-20 Thread Skip Montanaro
 Are you familiar with emacs' org mode tables?

 http://orgmode.org/org.html#Tables

No. Thanks for the pointer.

S
-- 
https://mail.python.org/mailman/listinfo/python-list