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

发布于 2024-07-14 02:48:47 字数 172 浏览 8 评论 0原文

寻找一种以编程方式将注释(使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲在坟头点根烟 2024-07-21 02:48:47

这就是我所做的:

  1. 用word创建一个简单的文档(即非常小的文档)
  2. 在Word中添加注释
  3. 另存为docx。
  4. 使用python的zip模块来访问存档(docx文件是ZIP存档)。
  5. 转储存档中条目“word/document.xml”的内容。 这是文档本身的 XML。

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

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

Here is what I did:

  1. Create a simple document with word (i.e. a very small one)
  2. Add a comment in Word
  3. Save as docx.
  4. Use the zip module of python to access the archive (docx files are ZIP archives).
  5. Dump the content of the entry "word/document.xml" in the archive. This is the XML of the document itself.

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

缱绻入梦 2024-07-21 02:48:47

如果这是服务器端(非交互式),则不支持使用 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文