【问题标题】:Decrypt XLS file with Python for pandas使用 Python for pandas 解密 XLS 文件
【发布时间】:2022-02-04 02:47:11
【问题描述】:

我正在尝试解密要读入数据帧的 XLS 文件。我在 Linux 系统上,所以 xlwings 和 win32com 是不可能的。我也尝试过使用 msoffcrypto-tool 但似乎 XLS 仍处于实验阶段,因此它也不适用于我的文件。以前有人遇到过这个问题吗?

【问题讨论】:

  • “解密”是什么意思?你有密码吗?或者你有什么发现它的?

标签: python linux xls


【解决方案1】:

很多人想要加密/解密文件。您需要知道它是用什么加密的,可能还有其他信息才能解密它。

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)

【讨论】:

    【解决方案2】:

    我遇到了和你非常相似的问题。我不确定您的 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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 2016-02-01
      • 2021-09-16
      • 2019-06-10
      • 1970-01-01
      相关资源
      最近更新 更多