我正在尝试读取.xls文件。当我尝试用XLRD打开它时,我得到了以下信息。工作表在Excel.but中可以正常打开,我无法找到有关此错误的更多信息:
Traceback (most recent call last):
File "./art.py", line 7, in <module>
workbook = xlrd.open_workbook("/opt/zir/data/input/May2020executions.xls")
File "/usr/local/lib/python3.6/site-packages/xlrd/__init__.py", line 157, in open_workbook ragged_rows=ragged_rows,
File "/usr/local/lib/python3.6/site-packages/xlrd/book.py", line 88, in open_workbook_xls ragged_rows=ragged_rows,
File "/usr/local/lib/python3.6/site-packages/xlrd/book.py", line 632, in biff2_8_load
cd = compdoc.CompDoc(self.filestr, logfile=self.logfile)
File "/usr/local/lib/python3.6/site-packages/xlrd/compdoc.py", line 90, in __init__
raise CompDocError('Expected "little-endian" marker, found %r' % mem[28:30])
xlrd.compdoc.CompDocError: Expected "little-endian" marker, found b'\xff\xfe'任何帮助都是最好的。我在这里迷路了。如果我把它加载到Excel中,并保存为.xlsx,它可以工作,我以为XLRD读取的是.xls文件.
发布于 2020-08-07 11:24:54
import xlrd
file_path = r'test.xlsx'
def read_file():
table = xlrd.open_workbook(file_path)
sheet = table.sheet_by_name('Sheet1')
print(table.sheet_names())
print(sheet.ncols)
print(sheet.nrows)
print(sheet.cell(1, 0).value)
for row in range(0, sheet.nrows):
for col in range(0, sheet.ncols):
print(sheet.cell(row, col).value, end='------')
print('')
if __name__ == '__main__':
read_file()你可以试试这个。
发布于 2020-08-07 11:29:54
除非您必须使用XLRD,否则另一种选择是在Pandas中读取文件
import pandas as pd
workbook = pd.read_excel("/opt/zir/data/input/May2020executions.xls")https://stackoverflow.com/questions/63294374
复制相似问题