Why is python xlrd errors when opening a .xlsm instead of .xls

本小妞迷上赌 提交于 2021-01-28 05:24:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!