用panda加载xls文件失败



我正在尝试使用加载带有panda的xls文件

pd.read_excel(fi_name, sheet_name=None, engine=None)

但我得到了这个错误:

"XLRDError: Workbook is encrypted"

但文件并没有加密,我可以用excel打开它,并用tika包读取文件的文本。

有人知道我该怎么解决吗?

此外,有人知道一个用于读取所有excel文件格式的python包吗,即使熊猫失败了?

感谢

我想,我找到了解决您问题的方法:

import msoffcrypto
file = msoffcrypto.OfficeFile (open ('encrypted.xls', 'rb')) # read the original file
file.load_key (password = 'VelvetSweatshop') # Fill in the password, if it can be opened directly, the default password is 'VelvetSweatshop'
file.decrypt (open ('decrypted.xls', 'wb')) # Save it as a new file after decryption

之后,您可以使用xlrd来正常打开和操作解密后的文件。

你可以用安装软件包

pip install msoffcrypto

你可以在这里看到完整的文档

这有两个可能的原因:

  1. 您得到的文件与文件扩展名所说的文件格式不同。

  2. 整个工作簿或其中的一页都受密码保护,因此从中读取的数据会被加密以保护数据。

最新更新