简体   繁体   中英

pyExcelerator has problems reading some files

I've got a problem using pyExcelerator when reading some xls-files.

There're some python scripts i wrote, that use this library to parse XLS-files and populate database with info.

The templates for the files these scripts parse may vary and i sometimes reconfigure the script to handle them. With the one of the templates i ran into problem: pyExcelerator just raises an exception:

Traceback (most recent call last):
 File "/home/* * */parsexls.py",
line 64, in handle_label
   parser.parse()
 File "/home/* * */parsers.py", line 335, in parse
   self.contents = pyExcelerator.parse_xls(self.file_record.file,
self.encoding)
 File "/usr/local/lib/python2.6/dist-packages/pyExcelerator/ImportXLS.py",
line 327, in parse_xls
   ole_streams = CompoundDoc.Reader(filename).STREAMS
 File "/usr/local/lib/python2.6/dist-packages/pyExcelerator/CompoundDoc.py",
line 67, in __init__
   self.__build_short_sectors_data()
 File "/usr/local/lib/python2.6/dist-packages/pyExcelerator/CompoundDoc.py",
line 256, in __build_short_sectors_data
   dentry_start_sid, stream_size) = self.dir_entry_list[0]
IndexError: list index out of range

Some of the problem XLS-files contained empty sheets and removing of these sheets helped, but many of the files can't be handled even without empty sheets. There's nothing extraordinary in these files and they contain no formulas or pictures - just strings, numbers and dates.

As i can see, the pyExcelerator is abandoned by it's author :(

Any suggestions on fixing this issue are much appreciated.

I'm the author of xlrd. It r ea d s XLS files and is not a fork of anything. I maintain a package called xlwt which w ri t es XLS files and is a fork of pyExcelerator. The parse_xls functionality in pyExcelerator was deprecated to the point of removal from xlwt. Use xlrd instead.

Given the traceback that you reproduced, it looks like the file may be corrupted. What it is doing there happens well before the sheet data is parsed. What software produces these files? Can you open them with Excel or OpenOffice.org's Calc or Gnumeric? xlrd may give you a more meaningful error message. You may like to send me (insert_punctuation('sjmachin', 'lexicon', 'net')) copies of your failing file(s); please include some with and some without empty sheets. By the way, what are you using to remove empty sheets? What error message do you get from pyExcelerator when processing files with empty sheets?

You might wish to give xlrd a try... it started (I believe) as a fork of pyExcelerator, so incorporating requires few code changes, but it is actively maintained:

http://pypi.python.org/pypi/xlrd

Project website

General info, release notes and history from the documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM