如何在 Word 文件中查找数学方程式,如果找到则使用 vsto c# 突出显示它

How to find math equation in Word file and if found then highlighted it using vsto c#

如何在 Word 文件中找到数学公式?

请提出相同的建议。

我的输出会变成这样:

使用下面的 C# 代码以黄色突出显示所有 MathType 方程。 在使用此代码之前,请在 class 文件的命名空间声明中添加 using Word = Microsoft.Office.Interop.Word;

public bool FindAndHighlightMathtypeEquation(ref Word.Range myRange)
    {
        try
        {
            int inlineShapesCount = myRange.InlineShapes.Count;
            if (inlineShapesCount > 0)
            {
                for (int i = 1; i <= inlineShapesCount; i++)
                {
                    Word.InlineShape currentShape = myRange.InlineShapes[i];
                    Word.Range currentShapeRange = currentShape.Range;
                    Word.WdInlineShapeType typeOfCurrentShape = currentShape.Type;

                    if (typeOfCurrentShape != Word.WdInlineShapeType.wdInlineShapeEmbeddedOLEObject)
                    {
                        continue;
                    }

                    if (!currentShape.Field.Code.Text.Trim().ToLower().Contains("equation"))
                    {
                        continue;
                    }

                    currentShapeRange.Select();
                    currentShapeRange.Application.Selection.Range.HighlightColorIndex = Word.WdColorIndex.wdYellow;
                }
            }

            MessageBox.Show("Process Completed");

        }
        catch (Exception)
        {
            throw;
        }
        return true;
    }

有一种简单的方法可以在 Word 中突出显示所有字段。转到 Word 选项,高级,然后在显示文档内容下,选择 "field shading" 选项中的 "always"。 遗憾的是它是灰色的而不是黄色的,但仍然非常有用。