我正在使用以下代码在我的文档中查找一些字符串:Application application = Addin.Application;Document document = application.ActiveDocument;Range rng = document.Content;rng.Find.ClearFormatting();rng.Find.Forward = true;rng.Find.Text = findText;while (rng.Find.Execute() && rng.Find.Found){ //here: rng.Text == findText //however rng.Find.HitHighlight(findText, WdColor.wdColorAqua); //highlights all occurrences in the document, not in the current range}作为代码状态中的注释,我希望rng.Find.HitHighlight(findText, WdColor.wdColorAqua);只在当前范围内工作,而是在整个文档上执行。有趣的是,如果我从不同的范围开始,这将按我的预期工作......即。Range rng = document.Content.Paragraphs.First.Range;rng.Find.HitHighlight("video", WdColor.wdColorAqua);只会HitHighlight在findText第一段中。这是不一致的......关于如何HitHighlight仅在使用选择的范围内执行的任何想法Find?注意:我在 NetOffice 插件中尝试过这个,我得到了相同的行为。
1 回答

慕田峪4524236
TA贡献1875条经验 获得超5个赞
似乎该Find.HitHighlight
方法不打算与Find.Execute
. 它似乎使用您调用时存在的任何范围Execute
。如果你不调用执行,它使用当前范围。
评论
当 Word 被指定为电子邮件编辑器时,HitHighlight 方法主要适用于 Office Outlook 中的搜索突出显示。但是,如果要突出显示找到的文本,可以在 Word 中的文档上使用此方法。否则,使用 Execute 方法。
我怀疑除了遍历您已经知道的每个段落之外,没有其他方法可以做到这一点。
我意识到这不是一个完整的答案,但 VSTO 不是一个流行的标签,这可能是你会得到的最好的。大多数问题完全没有答案,而且通常也没有评论。
- 1 回答
- 0 关注
- 135 浏览
添加回答
举报
0/150
提交
取消