Python Xlrd读取Excel文件错误 [英] Python Xlrd read excel file error

查看:159
本文介绍了Python Xlrd读取Excel文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Windows上编写脚本,现在将平台更改为Linux/Ubuntu时遇到了一些问题.在下面的示例中,我只是尝试打印工作表名称,但收到了一些我从未见过的错误.Xlrd可能有问题吗?因为我可以在Libreoffice中打开Excel文件.

I have been working on a script on Windows and now when changing the platform to Linux/Ubuntu I am having some issues. In the example below I am just trying to print the sheetnames but receicing some errors which I have never seen before. May this be a issue with Xlrd ? Because I am able to open the Excel file in Libreoffice.

代码:

#!/usr/bin/python
import xlrd

xl_workbook = xlrd.open_workbook('/home/ubuntu/Downloads/usage01.12.2015_31.12.2015.xls')

sheet_names = xl_workbook.sheet_names()
print('Sheet Names', sheet_names)

错误:

    0  5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
   20  4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
   40= 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
   60  4 4 3 2
Traceback (most recent call last):
  File "./forbruk.py", line 4, in <module>
    xl_workbook = xlrd.open_workbook('/home/ubuntu/Downloads/usage01.12.2015_31.12.2015.xls')
  File "/usr/local/lib/python2.7/dist-packages/xlrd-0.9.4-py2.7.egg/xlrd/__init__.py", line 441, in open_workbook
    ragged_rows=ragged_rows,
  File "/usr/local/lib/python2.7/dist-packages/xlrd-0.9.4-py2.7.egg/xlrd/book.py", line 87, in open_workbook_xls
    ragged_rows=ragged_rows,
  File "/usr/local/lib/python2.7/dist-packages/xlrd-0.9.4-py2.7.egg/xlrd/book.py", line 592, in biff2_8_load
    cd.locate_named_stream(UNICODE_LITERAL(qname))
  File "/usr/local/lib/python2.7/dist-packages/xlrd-0.9.4-py2.7.egg/xlrd/compdoc.py", line 390, in locate_named_stream
    d.tot_size, qname, d.DID+6)
  File "/usr/local/lib/python2.7/dist-packages/xlrd-0.9.4-py2.7.egg/xlrd/compdoc.py", line 418, in _locate_stream
    raise CompDocError("%s corruption: seen[%d] == %d" % (qname, s, self.seen[s]))
xlrd.compdoc.CompDocError: Workbook corruption: seen[2] == 4

推荐答案

如果您需要来自远程服务的数据,这是一种黑客行为,但注释掉第418行(引发CompDocError(%s损坏:见过[%d] ==%d%(qname,s,self.seen [s])))似乎可以正常工作.

If you need data from a remote service, it's a hack, but commenting out line 418 (raise CompDocError("%s corruption: seen[%d] == %d" % (qname, s, self.seen[s]))) in compdoc.py seems to work okay.

也请查看此文档

这篇关于Python Xlrd读取Excel文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆