IndexError:索引超出范围:在xlrd中选择xls时

时间:2020-04-04 13:39:30

标签: python excel xlrd

我有一个相当小众的问题,我只是无法深入了解。

我从第三方收到xls文件,事实证明在xlrd中解析它们很麻烦-每当我将其加载时,我都会收到错误消息:

--> 312     options = BYTES_ORD(data[pos])
    313     pos += 1
    314     phonetic = options & 0x04

IndexError: index out of range

在Excel中打开它们时,我收到错误消息:

PROTECTED VIEW: Office has detected a problem with this file, editing it may harm your computer

但是该文件实际上是打开的,并在保存后以xlsx格式进行解析。

我什至无法开始诊断问题所在……

完整追溯:


IndexError                                Traceback (most recent call last)
<ipython-input-130-0e9a3a712fe6> in <module>
      3 
      4 
----> 5 xlrd.open_workbook('bnp.xls')

~/anaconda3/lib/python3.7/site-packages/xlrd/__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
    155         formatting_info=formatting_info,
    156         on_demand=on_demand,
--> 157         ragged_rows=ragged_rows,
    158     )
    159     return bk

~/anaconda3/lib/python3.7/site-packages/xlrd/book.py in open_workbook_xls(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
    115                 bk.on_demand = on_demand = False
    116         else:
--> 117             bk.parse_globals()
    118             bk._sheet_list = [None for sh in bk._sheet_names]
    119             if not on_demand:

~/anaconda3/lib/python3.7/site-packages/xlrd/book.py in parse_globals(self)
   1231                 self.handle_sheethdr(data)
   1232             elif rc == XL_SUPBOOK:
-> 1233                 self.handle_supbook(data)
   1234             elif rc == XL_NAME:
   1235                 self.handle_name(data)

~/anaconda3/lib/python3.7/site-packages/xlrd/book.py in handle_supbook(self, data)
   1105             if blah: print("SUPBOOK[%d]: add-in functions" % sbn, file=self.logfile)
   1106             return
-> 1107         url, pos = unpack_unicode_update_pos(data, 2, lenlen=2)
   1108         if num_sheets == 0:
   1109             self._supbook_types[-1] = SUPBOOK_DDEOLE

~/anaconda3/lib/python3.7/site-packages/xlrd/biffh.py in unpack_unicode_update_pos(data, pos, lenlen, known_len)
    310         # Zero-length string with no options byte
    311         return (UNICODE_LITERAL(""), pos)
--> 312     options = BYTES_ORD(data[pos])
    313     pos += 1
    314     phonetic = options & 0x04

IndexError: index out of range

0 个答案:

没有答案