在MS WORD VSTO中,您可以按如下方式查找/替换文本颜色。我们能在MS WORD的new Office WORD-AddIn platform中实现同样的效果吗?我正在使用Office 2016。
public bool ReplaceFont(Word.Range rng, string findWhat)
{
bool hasFound = false;
rng.Find.ClearFormatting();
rng.Find.Replacement.ClearFormatting();
rng.Find.Replacement.Font.ColorIndex = Word.WdColorIndex.wdBlue;
rng.Find.Text = findWhat;
rng.Find.Replacement.Text = findWhat;
rng.Find.Forward = true;
rng.Find.Wrap = Word.WdFindWrap.wdFindStop;
//change this property to true as we want to replace format
rng.Find.Format = true;
hasFound = rng.Find.Execute(Replace: Word.WdReplace.wdReplaceAll);
return hasFound;
}发布于 2018-10-05 05:50:39
尝试使用Body.search方法查找范围。然后遍历返回的范围以设置Range.font.color属性。
https://stackoverflow.com/questions/52655330
复制相似问题