Microsoft Word 中的拼写错误
我正在处理 Microsoft Word 中的拼写错误。只要有几个拼写错误,访问 SpellingErrors 集合就会变得非常慢(至少对于 For/Next 或 For/Each 循环而言)。
有没有办法快速获取列表(制作副本、复制条目、停止集合的动态性质)?我只需要一个列表,它的快照,并且它不是动态的或实时的。
I am working with misspellings in Microsoft Word. With only just a few misspellings, accessing the SpellingErrors collection becomes gawdawful slow (at least with For/Next or For/Each loops).
Is there a way to get the to the list (make a copy, copy the entries, stop the dynamic nature of the collection) quickly? I just need a list, a snap shot of it, and for it not to be dynamic or real time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我模拟创建和检查拼写错误的方法:
在我这边进行的测试在 Word 2003 和 Word 2010 中运行得非常快。请注意,这会给您六个拼写错误,而不是四个。虽然“beet”和“rite”是英语单词,但在这句话的上下文中它们被认为是“拼写错误”。
请注意
Application.Options.CheckSpellingAsYouType = False
。这将关闭自动拼写错误检测(红色波浪线)。这是一个应用程序范围的设置 - 不仅仅是针对单个文档 - 因此最好的做法是重新打开它,如果这是最终用户在 Word 中所期望的,就像我在最后所做的那样。现在,如果在 Word 2007/2010 中启用检测(这不适用于 2003 及更早版本),您只需读取 XML (WordprocessingML) 中拼写错误的单词即可。该解决方案的设置和管理更加复杂,并且只有在您不使用 VBA 而是使用 Open XML 进行编程时才应该使用。使用 Linq-to-XML 进行简单的查询就足以获得所有拼写错误的单词的 IEnumerable。您将转储每个
w:type="spellStart"
和w:type="spellEnd"
属性之间的 XML 的所有.Value
元素。上面生成的文档在 WordprocessingML 中有这样一段:Here's how I would simulate creating and checking spelling errors:
Testing this on my side runs extremely fast, both in Word 2003 and Word 2010. Note that this will give you six spelling errors, not four. Although "beet" and "rite" are words in English, they are considered "misspelled" in the context of this sentence.
Notice the
Application.Options.CheckSpellingAsYouType = False
. This turns off automatic spelling error detection (red squigglies). It is an application-wide setting - not just for a single document - so best practice would be to turn it back on if that is what the end-user is expecting in Word as I've done at the end.Now if detection is on in Word 2007/2010 (this doesn't work for 2003 and earlier), you can simply read the misspelled words in the XML (WordprocessingML). This solution is more complicated to set up and manage, and should really only be used if you're not using VBA to program but rather Open XML. A simple query with Linq-to-XML would suffice to get an IEnumerable of all the misspelled words. You would dump all the
.Value
of the XML between eachw:type="spellStart"
andw:type="spellEnd"
attributes of the<w:proofErr/>
element. The document produced above has this paragraph in WordprocessingML: