简体   繁体   中英

KeyError: u'xl/worksheets/Sheet1.xml' is given when try to open xlsx file with python xlrd

I can not process some files using python xlrd library. This is my code,

>>> from xlrd import open_workbook, XLRDError
>>> try:
...     book = open_workbook('17112015Rpt1000000178_Report.xlsx')
... except XLRDError as e:
...     print e
... 

I get the following error.

     Traceback (most recent call last):
          File "<stdin>", line 2, in <module>
          File "/usr/local/lib/python2.7/dist-packages/xlrd/__init__.py", line 422, in open_workbook
            ragged_rows=ragged_rows,
          File "/usr/local/lib/python2.7/dist-packages/xlrd/xlsx.py", line 790, in open_workbook_2007_xml
            zflo = zf.open(component_names[fname])
KeyError: u'xl/worksheets/Sheet1.xml' 

How to fix this issue?

I got the same Error Message You may consider upgrade your xlrd Package.

First upgrade your pip (to avoid problems) Then upgrade xlrd

usage:

  python -m pip install --upgrade pip
  pip install xlrd -U

It worked for me... Good luck!!

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