【问题标题】:C# MSword doesnt highlight whole word when using Find and matchAllWordForms=true使用 Find 和 matchAllWordForms=true 时 C# MS word 不突出显示整个单词
【发布时间】:2012-06-22 00:24:03
【问题描述】:

在我的程序中,我使用Find.Execute 搜索关键字的所有单词形式并突出显示它们。例如,如果我的源文档包含“perform”和“performance”,Find.Execute(...matchAllWordForms=true...) 会找到这两个词,但只会突出显示 performance 的“perform”部分。

如何让 MSWord 突出显示整个单词? range.TextFind.Execute 更改为“执行”,所以我无法遍历它。我尝试执行Range.Select(),然后迭代Selection.End,但范围与原始文档不匹配。

任何帮助将不胜感激!

【问题讨论】:

    标签: c# ms-word selection highlight replace


    【解决方案1】:

    嗯,我觉得有点愚蠢:

    我试图使用 Selection.Extend 并完全错过了 Selection.Expand 选项。对于以后偶然发现此问题的任何人:

    range.Select();    // The range after Find.Execute
    wordApp.Selection.Expand(Word.WdUnits.wdWord);    // may have to trim off excess whitespace
    Word.Range highlightRange = document.Range(wordApp.Selection.Start, wordApp.Selection.End);
    wordApp.Selection.Shading.BackgroundPatternColor = (Word.WdColor)System.Drawing.ColorTranslator.ToOle(extractedColor);
    

    请注意,我使用 Shading 作为我的荧光笔(因此我可以使用 System.Drawing.Color.FromARGB(Alpha,R,G,B) 创建自定义颜色,而不是默认的 15 种颜色)。

    【讨论】:

    • 你好@Chris,欢迎来到 StackOverflow!如果这是您问题的解决方案,请不要忘记将其标记为正确答案。然后我们都可以看看是否有解决方案。 :-)
    • 是的,只是在等待等待计时器到期
    猜你喜欢
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多