如何以编程方式将注释插入Microsoft Word文档? [英] How to programmatically insert comments into a Microsoft Word document?

查看:96
本文介绍了如何以编程方式将注释插入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.

推荐答案

这就是我所做的:

  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

这篇关于如何以编程方式将注释插入Microsoft Word文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆