python-2.7 - 使用 docx 库打开有密码的 Word 文档

标签 python-2.7 ms-word

我正在尝试打开一个有密码的 word 文档。

我正在使用 docx 包 - 有点旧

from docx import opendocx, getdocumenttext

并进一步
 document = opendocx(filename)

我想知道 opendocx 上是否有允许它打开受密码保护的 Word 文档的选项——我知道密码。我在这里检查了 github 存储库:https://github.com/mikemaccana/python-docx 但没有看到选项。我试图避免重写代码以使用更新的包,但这可能是不可避免的。

最佳答案

python-docx 目前不支持密码。我也没有在代码中找到它,但可以肯定的是,我询问了 python-docx mailing listreceived 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 文件的一些信息:
  • Super User: How can I unlock a Microsoft .docx document?

  • 如果您不想更改代码,可以使用的一种方法是派生 docx 包并添加代码来解密 docx 文件。如果您有另一个程序来解密文档,您也可以进行解密。

    关于python-2.7 - 使用 docx 库打开有密码的 Word 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787340/

    相关文章:

    python - 在 Python 中从 UTF-8 解析为 XML

    Python:列表中的列表 - 将字符串添加到父列表中的项目而不影响子列表的函数?

    Python For 循环语法

    vba - 从字符串中删除段落标记

    java - 从网络打开 MS Word 文档

    windows - VBA:将多个 Word 文件合并为一个文件后,Microsoft Word 进程不会退出

    php - 通过 Php 提供 .docx 文件

    python - 计算一个字符串中有多少个数字

    Python raw_input 不接受输入

    java - 自定义 docx 文档中的颜色