I have an Excel spreadsheet full of parameters which I edit with
OpenOffice 3 on Solaris 10. It's later read using xlrd to generate
some config files. Up until today this worked just fine. Now I get
Traceback (most recent call last):
File "../scripts/generate_config_xml.py", line 38, in
get_params_dict
params_wb = xlrd.open_workbook(params_file)
File "/opt/app/g++lib6/python-2.4/lib/python2.4/site-packages/
xlrd-0.6.1-py2.4.egg/xlrd/__init__.py", line 370, in open_workbook
File "/opt/app/g++lib6/python-2.4/lib/python2.4/site-packages/
xlrd-0.6.1-py2.4.egg/xlrd/__init__.py", line 1323, in getbof
Poking around with Google I saw some suggestions that it was in XML
format. Pulled it up in Emacs. Looked like binary to me.
Here's what I've done so far:
* Removed the column I added this morning. Didn't help.
* Tried making a trivial edit then saving in the usual way (format
shows as Microsoft Excel 97/2000/XP in the Save As dialog).
* Tried saving it as Microsoft Excel 95. This did not help
* Sent it to a friend with real honest-to-goodness Excel. Had him
make a trivial edit, save, then send it back. He said it opened
in "compatibility mode". This also did not help.
* Checked versions of the code and programs. Nothing has changed.
* Tried my config generator with a different version of the file
(one checked in on a different branch in Subversion). This
worked fine.
I know we're not up-to-date on xlrd, but honestly, this worked
yesterday. I can't think of what might have changed to cause this
breakage. Any ideas?
John> print "params_file:", repr(params_file)
John> print "realpath:", repr(os.path.realpath(params_file))
John> f = open(params_file, 'rb')
John> print "first 20 bytes:", repr(f.read(20))
John> f.close()
Seems pretty unlikely, since I name the spreadsheet file on the command
line. Still, I will add such code if I continue to have problems. I spent
the day working on other stuff and just came back to this. I figured I'd
run it once more to verify the problem, then add your code. Faith and
Begora! It ran fine. I am completely flummoxed at this point. I verified
that I was working with the same file indirectly. First, I ran it against a
new file which expected the new column. It complained that the column was
missing. I went back to OO, added the column, ran again, and it worked.
Skip
XLSX is actually a collection of XML files in a ZIP archive, so it
would indeed look like binary if you opened it up in Emacs. I have no
idea whether this is at all related to your problem, though.
Ian> XLSX is actually a collection of XML files in a ZIP archive, so it
Ian> would indeed look like binary if you opened it up in Emacs. I have
Ian> no idea whether this is at all related to your problem, though.
Right, but the version of OO I run can't generate XLSX files. (As I recall
it can read them.) The most recent format it can write is Excel 97/2000/XP
workbooks I believe. I will try an unzip -t if this happens again (and I
remember), but at the moment at least the file in question is no such beast:
% unzip -t params.xls
Archive: params.xls
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
note: params.xls may be a plain executable, not an archive
unzip: cannot find zipfile directory in one of params.xls or
params.xls.zip, and cannot find params.xls.ZIP, period.
OTOH, a .xlsx file I have laying around:
% unzip -t Putin_parameters\ sept\ 2010\ to\ publish.xlsx
Archive: Putin_parameters sept 2010 to publish.xlsx
testing: [Content_Types].xml OK
testing: _rels/.rels OK
testing: xl/_rels/workbook.xml.rels OK
testing: xl/workbook.xml OK
testing: xl/theme/theme1.xml OK
testing: xl/worksheets/_rels/sheet1.xml.rels OK
testing: xl/worksheets/sheet2.xml OK
testing: xl/worksheets/sheet3.xml OK
testing: xl/worksheets/sheet1.xml OK
testing: xl/sharedStrings.xml OK
testing: xl/styles.xml OK
testing: xl/printerSettings/printerSettings1.bin OK
testing: docProps/core.xml OK
testing: docProps/app.xml OK
No errors detected in compressed data of Putin_parameters sept 2010 to publish.xlsx.
I have NeoOffice on my Mac which can write XLSX files. It's possible that I
inadvertently edited it there and saved in that format, however I see no
evidence in the Recent Documents list that I've visited this particular
spreadsheet using that tool.
Thanks for all the feedback. I will have more diagnostic weapons in my
arsenal if this happens again.
Skip
>> Poking around with Google I saw some suggestions that it was in XML
>> format. Pulled it up in Emacs. Looked like binary to me.Ian> XLSX is actually a collection of XML files in a ZIP archive, so it
Ian> would indeed look like binary if you opened it up in Emacs. I have
Ian> no idea whether this is at all related to your problem, though.
John> Check to see whether your manual operations and your script are
John> referring to different paths. Consider putting some debug code in
John> your script just in front of the call to xlrd.open_workbook:John> print "params_file:", repr(params_file)
John> print "realpath:", repr(os.path.realpath(params_file))
John> f = open(params_file, 'rb')
John> print "first 20 bytes:", repr(f.read(20))
John> f.close()Seems pretty unlikely, since I name the spreadsheet file on the command
line.
Still, I will add such code if I continue to have problems. I spent
the day working on other stuff and just came back to this. I figured I'd
run it once more to verify the problem, then add your code. Faith and
Begora! It ran fine. I am completely flummoxed at this point. I verified
that I was working with the same file indirectly. First, I ran it against a
new file which expected the new column. It complained that the column was
missing. I went back to OO, added the column, ran again, and it worked.