如何在 Word 中强调文本而不改变文档,就像在 Grammarly 中一样 [英] How to emphasise text in Word, without alter the document, like in Grammarly

查看:51
本文介绍了如何在 Word 中强调文本而不改变文档,就像在 Grammarly 中一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Word(以及 Outlook)编写 VSTO 插件.我想强调文本的某些部分(检测到的错误).据我所知,Microsoft.Office.Interop.Word 或其他库中没有这种强调的 API.

I am writing a VSTO add-inn to Word (and Outlook as well). I want to emphasize certain parts of the text (detected errors). As far as I know, there is no API for this kind of emphasizing in Microsoft.Office.Interop.Word or other libraries.

但是 Grammarly (www.grammarly.com) 已经找到了一种方法:

But Grammarly (www.grammarly.com) has found a way to do it:

有谁知道你怎么能用同样的方式做到这一点?

Does anyone know how you can do it the same way?

推荐答案

我认为最好的方法是将所需文本放入 Range 中,然后应用以下格式:

I believe that the best way to do this would be to place the desired text into a Range and then apply the following formatting:

myRange.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
myRange.Font.UnderlineColor = Microsoft.Office.Interop.Word.WdColor.wdColorRed;

这将如何与 Grammerly 一起使用

正如之前在问题的评论中指出的那样,添加重点的唯一方法是临时更改文档,这似乎是 Grammerly 以非常聪明的方式所做的.Grammerly 仅在单击 Grammerly 功能区上的 Open Grammerly 按钮时才起作用.如果你做一个简单的实验,你或许可以观察到 Grammerly 是如何控制它的临时变化的.

As previously pointed out in the comments for the question, the only way to add the emphasis is to change the document temporarily, which is what Grammerly seems to do in a very smart way. Grammerly only works when one clicks the Open Grammerly button on the Grammerly ribbon. If you do a simple experiment, you may be able to observe how Grammerly controls its temporary changes.

首先创建一个未保存的文档,其中包含一些显示红色波浪线的拼写错误的单词.然后单击Open Grammerly 按钮.请注意,加载项关闭拼写检查,并将其替换为它自己在文档中生成的 Web 触发标记,类似于上面代码生成的标记.然后保存文档.如果仔细观察,您会看到一个小小的眨眼,其中红色粗下划线会暂时消失.那是 Document.BeforeSave 事件在保存文档之前删除它们的标记.通过依赖用户操作,Grammerly 控制标记出现的时间点.然后它使用代码和事件来确保标记不会与文档一起保存或干扰其他操作.

First create an unsaved document with some misspelled words that show the wavy red line. Then click the Open Grammerly button. Notice that the add-in turns off spell checking and replaces it with its own web-triggered markings that are generated in the document and similar to what is generated by the code above. Then save the document. If you look carefully, you will see a small blink wherein the red thick underlines disappear for a brief moment. That is the Document.BeforeSave event removing their markings before saving the document. By relying on user actions, Grammerly controls at what points in time the markings appear. It then uses code and events to make sure the markings are not saved with the document or interfere with other operations.

您可能想要查看的一些事件是:

Some of the events you may want to look at are the:

Document.BeforeSave 事件

Document.BeforePrint 事件

Document.BeforeClose 事件

这篇关于如何在 Word 中强调文本而不改变文档,就像在 Grammarly 中一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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