【问题标题】:Highlight all occurrences of a string in Word using VSTO使用 VSTO 突出显示 Word 中所有出现的字符串
【发布时间】:2014-01-18 23:53:59
【问题描述】:

我想使用 VSTO 突出显示在 Microsoft Word 2010 中出现的所有给定字符串。

到目前为止,我已经成功地使用Find 工具为匹配项设置了前景色:

Word.Find find = Application.ActiveDocument.Content.Find;
find.Replacement.Font.ColorIndexBi = Word.WdColorIndex.wdYellow;
find.Execute(FindText: "dog", MatchCase: false, Replace: Word.WdReplace.wdReplaceAll);

但是,我想为比赛设置高亮,如下面的截图所示:

【问题讨论】:

  • VBA 中的记录建议您通过将 Application.Options.DefaultHighlightColorIndex 设置为 wdColorIndex 成员之一(例如 wdYellow)来设置突出显示颜色,并使用查找在替换中应用突出显示颜色。 Replacement.Highlight = 真。可以通过 VSTO 获得吗?
  • @bibadia:谢谢,这很有效 :-) 如果您将评论复制到答案,我会接受。
  • 谢谢,完成 - 我通常会发现检查 VBA 方面更快,但不喜欢发布答案,除非我确定通过 PIA 等提供相同的选项。
  • 我遇到了一些我无法移植的 VBA sn-ps,但你的工作正常。

标签: c# ms-word vsto


【解决方案1】:

如果想要临时突出显示,可以使用HitHighlight 方法代替:

Word.Find find = Application.ActiveDocument.Content.Find;
find.HitHighlight(
    FindText: "dog",
    MatchCase: false,
    HighlightColor: Word.WdColor.wdYellow);

【讨论】:

    【解决方案2】:

    使用设置来设置高亮颜色

    Application.Options.DefaultHighlightColorIndex 
    

    到 wdColorIndex 成员之一(例如 wdYellow)

    在替换中应用高亮颜色

    find.Replacement.Highlight = True
    

    【讨论】:

      猜你喜欢
      • 2013-10-21
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2013-10-04
      • 2015-09-08
      • 2018-03-05
      • 1970-01-01
      • 2015-08-25
      相关资源
      最近更新 更多