问题
Python program opens .xls just fine but will not open .xlsm and immediately fails.
xlrd.open_workbook("Some filename.xlsm")
Error: Exception has occurred: AttributeError 'bytes' object has no attribute 'seek'
Any help would be greatly appreciated...
回答1:
For those who run into this. The solution is to read the file via binary into a variable to avoid the open_workbook library for loading the file... it has something to do with the file coded utf-16-le i think... anyways here is a snippet of what needs to happen.
with open(FilePath, 'rb') as tmp_file:
tmp_excel=tmp_file.read()
tmp_file.close
objExcel=xlrd.open_workbook(file_contents=tmp_excel)
回答2:
In xlrd there is a test of the file type. Somehow the file type of an .xlsm document is not '.xls'. For version 1.2.0 of xlrd this not an issue.
来源:https://stackoverflow.com/questions/55109911/why-is-python-xlrd-errors-when-opening-a-xlsm-instead-of-xls