如何以编程方式将注释插入 Microsoft Word 文档?
寻找一种以编程方式将注释(使用 Word 中的注释功能)插入 MS Word 文档中的特定位置的方法。 我更喜欢一种可在最新版本的 MS Word 标准格式中使用并可在非 Windows 环境中实现的方法(最好使用 Python 和/或 Common Lisp)。 我一直在研究 OpenXML SDK,但似乎找不到解决方案。
Looking for a way to programmatically insert comments (using the comments feature in Word) into a specific location in a MS Word document. I would prefer an approach that is usable across recent versions of MS Word standard formats and implementable in a non-Windows environment (ideally using Python and/or Common Lisp). I have been looking at the OpenXML SDK but can't seem to find a solution there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我所做的:
这应该会让您知道您需要做什么。 之后,您可以使用 Python 中的 XML 库之一来解析文档,对其进行更改并将其添加回扩展名为“.docx”的新 ZIP 存档中。 只需复制原始 ZIP 中的所有其他条目,您就拥有了一个新的有效 Word 文档。
还有一个库可能会有所帮助:openxmllib
Here is what I did:
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.
There is also a library which might help: openxmllib
如果这是服务器端(非交互式),则不支持使用 Word 应用程序本身(但我认为这不适用)。 因此,要么采用该路线,要么使用 OpenXML SDK 来学习标记需要创建评论。 有了这些知识,一切都与操纵数据有关。
.docx 格式是具有定义结构的 XML 文件的 ZIP,因此大多数情况下,一旦您进入 ZIP 并获得正确的 XML 文件,修改 XML DOM 就变成了问题。
最好的方法可能是获取一个 docx,复制它,添加注释(使用 Word),然后进行比较。 diff 将向您显示需要在 SDK(或 ISO/Ecma 标准)中查找的元素/结构类型。
If this is server side (non-interactive) use of the Word application itself is unsupported (but I see this is not applicable). So either take that route or use the OpenXML SDK to learn the markup needed to create a comment. With that knowledge it is all about manipulating data.
The .docx format is a ZIP of XML files with a defines structure, so mostly once you get into the ZIP and get the right XML file it becomes a matter of modifying an XML DOM.
The best route might be to take a docx, copy it, add a comment (using Word) to one, and compare. A diff will show you the kind of elements/structures you need to be looking up in the SDK (or ISO/Ecma standard).