首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用新的Office插件以编程方式搜索和替换Word中的字体颜色

如何使用新的Office插件以编程方式搜索和替换Word中的字体颜色
EN

Stack Overflow用户
提问于 2018-10-05 05:22:01
回答 1查看 42关注 0票数 0

在MS WORD VSTO中,您可以按如下方式查找/替换文本颜色。我们能在MS WORDnew Office WORD-AddIn platform中实现同样的效果吗?我正在使用Office 2016。

代码语言:javascript
运行
复制
    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;
}
EN

回答 1

Stack Overflow用户

发布于 2018-10-05 05:50:39

尝试使用Body.search方法查找范围。然后遍历返回的范围以设置Range.font.color属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52655330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档