【发布时间】:2022-02-04 02:47:11
【问题描述】:
我正在尝试解密要读入数据帧的 XLS 文件。我在 Linux 系统上,所以 xlwings 和 win32com 是不可能的。我也尝试过使用 msoffcrypto-tool 但似乎 XLS 仍处于实验阶段,因此它也不适用于我的文件。以前有人遇到过这个问题吗?
【问题讨论】:
-
“解密”是什么意思?你有密码吗?或者你有什么发现它的?
我正在尝试解密要读入数据帧的 XLS 文件。我在 Linux 系统上,所以 xlwings 和 win32com 是不可能的。我也尝试过使用 msoffcrypto-tool 但似乎 XLS 仍处于实验阶段,因此它也不适用于我的文件。以前有人遇到过这个问题吗?
【问题讨论】:
很多人想要加密/解密文件。您需要知道它是用什么加密的,可能还有其他信息才能解密它。
b64解码进程的here is an example:
import base64
import io
import pandas as pd
with open('encoded_data.txt','rb') as d:
data=d.read()
print(data)
decrypted=base64.b64decode(data)
print(decrypted)
xls_filelike = io.BytesIO(decrypted)
df = pd.read_excel(xls_filelike, worksheet=0)
【讨论】:
我遇到了和你非常相似的问题。我不确定您的 xls 文件有什么问题,但我能够相当轻松地使用 msoffcrypto-tool。我希望我的解决方案可以帮助您解决问题,也可以帮助其他面临类似问题的人。在我的情况下,我能够在 Excel 中打开 xls 文件而不会提示输入密码,这意味着工作簿已使用默认密码“VelvetSweatshop”进行加密
import pandas as pd
import io
import msoffcrypto
file_path = "test.xls"
decrypted = io.BytesIO()
with open(file_path, "rb") as f:
data = msoffcrypto.OfficeFile(f)
# Default passwords for encrypted excel sheets
# Add your password here if it differs than the default
data.load_key(password="VelvetSweatshop")
data.decrypt(decrypted)
f = pd.read_excel(decrypted)
f.to_csv("test.csv")
【讨论】: