如何在 Word 文件中找到数学公式?
请提出相同的建议。
我的输出将是这样的:
使用下面的 C# 代码以黄色突出显示所有 MathType 方程。在使用此代码之前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 选项,高级,然后在显示文档内容下,在“字段底纹”选项中选择“始终”。可惜它是灰色而不是黄色,但同样非常有用。