Spire.Doc 文本教程(1):C# Word查找和替换功能

Spire.Doc系列教程之使用C#来实现word查找,替换和高亮显示功能。

下载Spire.Doc最新试用版

//新建一个word文档对象并加载sample文档Document document = new Document();document.LoadFromFile("Test.docx", FileFormat.Docx2010);//查找一个特定字符串 ”Spire.Doc”TextSelection selection = document.FindString("Spire.Doc", false, true);TextRange range = selection.GetAsOneRange();//替换字符串range.Text = "Replaced Text";//设置高亮颜色range.CharacterFormat.HighlightColor = Color.Yellow;//查找文档中所有字符串 ”Microsoft”TextSelection[] text = document.FindAllString("Microsoft", false, true);//设置高亮颜色foreach (TextSelection seletion in text){    seletion.GetAsOneRange().CharacterFormat.HighlightColor = Color.Green;}//使用 ”MS” 替换所有 ”Microsoft”document.Replace("Microsoft", "MS", false, true);//保存文档document.SaveToFile("Result.docx", FileFormat.Docx2010);

find and replace
想要购买正版授权,或者获取更多Spire.Doc相关信息的朋友可以点击” 咨询在线客服 “~

标签:文档管理Officeword文档处理

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年1月13日
下一篇 2019年1月13日

相关推荐

发表回复

登录后才能评论