为什么打开 .xlsm 而不是 .xls 时会出现 python xlrd 错误 [英] Why is python xlrd errors when opening a .xlsm instead of .xls
问题描述
Python 程序打开 .xls 就好了,但不会打开 .xlsm 并立即失败.
Python program opens .xls just fine but will not open .xlsm and immediately fails.
xlrd.open_workbook("Some filename.xlsm")
错误:发生异常:AttributeError'bytes' 对象没有属性 'seek'
Error: Exception has occurred: AttributeError 'bytes' object has no attribute 'seek'
任何帮助将不胜感激...
Any help would be greatly appreciated...
推荐答案
对于那些遇到这个问题的人.解决方案是通过二进制将文件读入一个变量,以避免使用 open_workbook 库来加载文件......我认为它与编码为 utf-16-le 的文件有关......无论如何这里是一个片段需要发生.
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)
这篇关于为什么打开 .xlsm 而不是 .xls 时会出现 python xlrd 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!