如何以编程方式使用 Microsoft Word 的拼写/语法检查器?
我想使用拼写/语法检查器处理中到大量的文本片段,以获得其“质量”的粗略近似值和排名。速度也不是真正重要的,所以我认为最简单的方法是编写一个脚本,将片段传递到 Microsoft Word (2007) 并对其运行拼写和语法检查器。
有没有办法通过脚本(特别是Python)来做到这一点?有哪些学习以编程方式控制 Word 的好资源?
如果没有,我想我可以尝试开源语法检查器(SO)中的一些东西。
更新
响应 Chris 的回答,是否至少有一种方法 a) 打开文件(包含代码片段),b) 从 Word 内部运行调用拼写和语法检查器的 VBA 脚本,以及 c) 返回片段“分数”的一些指示?
更新 2
我添加了一个似乎有效的答案,但如果有人有其他建议,我会将此问题保留一段时间。
I want to process a medium to large number of text snippets using a spelling/grammar checker to get a rough approximation and ranking of their "quality." Speed is not really of concern either, so I think the easiest way is to write a script that passes off the snippets to Microsoft Word (2007) and runs its spelling and grammar checker on them.
Is there a way to do this from a script (specifically, Python)? What is a good resource for learning about controlling Word programmatically?
If not, I suppose I can try something from Open Source Grammar Checker (SO).
Update
In response to Chris' answer, is there at least a way to a) open a file (containing the snippet(s)), b) run a VBA script from inside Word that calls the spelling and grammar checker, and c) return some indication of the "score" of the snippet(s)?
Update 2
I've added an answer which seems to work, but if anyone has other suggestions I'll keep this question open for some time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然需要一些挖掘,但我认为我找到了一个有用的解决方案。遵循 http://www.nabble.com/ 的建议Edit-a-Word-document-programmatically-td19974320.html 我正在使用 win32com 模块(如果 SourceForge 链接不起作用,请根据 此 Stack Overflow 答案< /a> 您可以使用
pip
获取模块),它允许访问 Word 的 COM 对象。下面的代码很好地演示了这一点:它会生成与结果匹配的结果。
当从 Word 手动调用检查时,
It took some digging, but I think I found a useful solution. Following the advice at http://www.nabble.com/Edit-a-Word-document-programmatically-td19974320.html I'm using the win32com module (if the SourceForge link doesn't work, according to this Stack Overflow answer you can use
pip
to get the module), which allows access to Word's COM objects. The following code demonstrates this nicely:which produces
which match the results when invoking the check manually from Word.