簡體   English   中英

如何在 python 中讀取/打開受密碼保護的 xlsx 文件

[英]how to read/open password protected xlsx file in python

我使用cmd = "msoffcrypto-tool hello.xlsx decrypted.xlsx -p erh1" os.system(cmd)成功解密了 xlsx 文件

但是當我使用wb = load_workbook(inputFilePath, data_only=True)打開decrypted.xlsx

我收到很少的警告和錯誤,但它打開得很好,我想刪除這些錯誤

  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 55, in _convert
    value = expected_type(value)
ValueError: could not convert string to float: '(#REF!-40)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/worksheet/_reader.py", line 280, in parse_formatting
    cf = ConditionalFormatting.from_tree(element)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/serialisable.py", line 103, in from_tree
    return cls(**attrib)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/formatting/rule.py", line 57, in __init__
    self.val = val
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/formatting/rule.py", line 36, in __set__
    super(ValueDescriptor, self).__set__(instance, value)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 67, in __set__
    value = _convert(self.expected_type, value)
  File "/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/descriptors/base.py", line 57, in _convert
    raise TypeError('expected ' + str(expected_type))
TypeError: expected <class 'float'>

  warn(msg)
/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/worksheet/_reader.py:300: UserWarning: Data Validation extension is not supported and will be removed
  warn(msg)
/home/muhammadu/.local/lib/python3.8/site-packages/openpyxl/worksheet/_reader.py:300: UserWarning: Conditional Formatting extension is not supported and will be removed
  warn(msg)

還是有任何其他方法可以使用 python 解密 xlsx? 我使用msoffcrypto-tool

如果您有一行以xlwb ,則應確保在其后有正確的代碼。

要打開受保護的文件,您應該:

xlwb = xlApp.Workbooks.Open(filename, False, True, None, password)

這應該會奏效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM