且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式将注释插入Microsoft Word文档?

更新时间:2023-02-12 20:30:45

这就是我所做的:

  1. 用单词创建一个简单的文档(即很小的文档)
  2. 在Word中添加评论
  3. 另存为docx.
  4. 使用python的zip模块访问存档(docx文件是ZIP存档).
  5. 将条目"word/document.xml"的内容转储到存档中.这是文档本身的XML.

这应该使您知道您需要做什么.之后,您可以使用Python中的XML库之一来解析文档,对其进行更改,然后将其添加回扩展名为".docx"的新ZIP存档中.只需从原始ZIP中复制所有其他条目,您就会获得一个新的有效Word文档.

This should give you an idea what you need to do. After that, you can use one of the XML libraries in Python to parse the document, change it and add it back to a new ZIP archive with the extension ".docx". Simply copy every other entry from the original ZIP and you have a new, valid Word document.

还有一个库可能会帮助您: openxmllib

There is also a library which might help: openxmllib