我正在尝试从excel文件中提取数据,但不幸的是xlrd库纪录片没有打开该文件,并且引发了很多错误。作为参考,我有一个.xls文件,其中包含10余页的数据
我尝试使用xlrd库没有运气,这是我的代码:
import xlrd
file = "C:\TestAutomation\doc\Smart_CID.xls"
wb = xlrd.open_workbook(file)
print(wb.nsheets)
这是回溯:
Traceback (most recent call last):
File "C:/TestAutomation/src/XML_parser.py", line 7, in <module>
wb = xlrd.open_workbook(file)
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 157, in open_workbook
ragged_rows=ragged_rows,
File "C:\Python27\lib\site-packages\xlrd\book.py", line 92, in open_workbook_xls
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
File "C:\Python27\lib\site-packages\xlrd\book.py", line 1278, in getbof
bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
File "C:\Python27\lib\site-packages\xlrd\book.py", line 1272, in bof_error
raise XLRDError('Unsupported format, or corrupt file: ' + msg)
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '<?xml ve'
作为其他参考,此excel文件从公司网站生成,并创建excel文件和xml文件。如何打开此excel文件?
答案 0 :(得分:1)