【发布时间】:2017-03-20 18:28:18
【问题描述】:
使用 VSTO 和 C#,我试图让 Outlook 突出显示电子邮件正文中的特定单词。到目前为止,我已经能够使用以下代码完成此操作:
Outlook.MailItem mailItem = this.inspector.CurrentItem as Outlook.MailItem;
if (inspector.IsWordMail())
{
var outlookWordDocument = inspector.WordEditor as Word.Document;
if (outlookWordDocument == null || outlookWordDocument.Application.Selection == null)
{ return; }
var wordRange = outlookWordDocument.Application.Selection.Range;
Word.Find find_highlight = wordRange.Find;
find_highlight.HitHighlight("apples", Word.WdColor.wdColorDarkRed);
find_highlight.ClearHitHighlight(); // trying to clear for testing purposes, but does nothing
}
我的问题是 ClearHitHighlight() 函数没有清除任何东西。我可以清除的唯一方法是,如果我之后立即执行另一次搜索。请参阅下面的 cmets:
find_highlight.HitHighlight("apples"); //highlights "apples"
find_highlight.HitHighlight("oranges"); //highlights "oranges" too
find_highlight.ClearHitHighlight(); //does nothing
find_highlight.HitHighlight("pears"); //clears previous highlights, adds pears
作为替代方案,我可以通过格式化电子邮件的实际正文来突出显示文本,但这个 HitHighlight 函数似乎更合适 - 如果我能弄清楚如何在完成后清除标记!
任何帮助将不胜感激。
【问题讨论】: