我正在尝试打开一个有密码的 word 文档。
我正在使用 docx 包 - 有点旧
from docx import opendocx, getdocumenttext
并进一步
document = opendocx(filename)
我想知道 opendocx 上是否有允许它打开受密码保护的 Word 文档的选项——我知道密码。我在这里检查了 github 存储库:https://github.com/mikemaccana/python-docx 但没有看到选项。我试图避免重写代码以使用更新的包,但这可能是不可避免的。
最佳答案
python-docx 目前不支持密码。我也没有在代码中找到它,但可以肯定的是,我询问了 python-docx mailing list 和 received the following reply :
Sorry, no. At least there's no built-in feature for it. I'm not sure how all that works with Word, it might be worth some research.
If it uses the Zip archive's password protection, you could open the .docx file (which is a Zip at the top level), and then do something I'm sure to feed it in. Worst case you could save it as another zip without a password and use that. And of course the interim zip could be a StringIO in-memory file.
If they use their own encryption I expect it would be quite a bit harder :)
Docx 使用自己的加密,而不是 zip 加密。这样只需要加密内部内容。此处提供了有关解密 docx 文件的一些信息:
如果您不想更改代码,可以使用的一种方法是派生 docx 包并添加代码来解密 docx 文件。如果您有另一个程序来解密文档,您也可以进行解密。
关于python-2.7 - 使用 docx 库打开有密码的 Word 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787340/