Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

ms-word - 如何在Word中强调文本而不更改文档(例如在语法中)(How to emphasise text in Word, without alter the document, like in Grammarly)

I am writing a VSTO add-inn to Word (and Outlook as well).

(我正在为Word(以及Outlook)编写VSTO加载项。)

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.

(据我所知,Microsoft.Office.Interop.Word或其他库中没有用于这种强调的API。)

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

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

Word的语法运行时的Screendump

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

(有谁知道你可以用同样的方式做吗?)

  ask by Anders Finn J?rgensen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

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

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

How This Would Work With 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似乎很聪明的方法。)

Grammerly only works when one clicks the Open Grammerly button on the Grammerly ribbon.

(只有当人们单击Grammerly功能区上的Open Grammerly按钮时,Grammerly才起作用。)

If you do a simple experiment, you may be able to observe how Grammerly controls its temporary changes.

(如果您进行简单的实验,则可以观察Grammerly如何控制其临时更改。)

First create an unsaved document with some misspelled words that show the wavy red line.

(首先创建一个未保存的文档,其中包含一些拼写错误的单词,这些单词显示波浪线。)

Then click the Open Grammerly button.

(然后单击“ Open Grammerly按钮。)

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.

(那是Document.BeforeSave事件,在保存文档之前删除其标记。)

By relying on user actions, Grammerly controls at what points in time the markings appear.

(通过依靠用户的操作,Grammerly可以控制标记出现在什么时间点。)

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 Event

(Document.BeforeSave事件)

Document.BeforePrint Event

(Document.BeforePrint事件)

Document.BeforeClose Event

(Document.BeforeClose事件)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...