Word控件Spire.Doc 【文本】教程(21) ;如何在 C# 中用 Word 文档替换文本

我们将给您介绍如何在 C#、VB.NET 下检索 Word 中所有 TextRanges 的样式名称

模板文件:

在 C# 中用 Word 文档替换文本

替换文本的文档:

在 C# 中用 Word 文档替换文本

详细步骤:

第 1 步:加载模板文档。

Document document = new Document("Template.docx");

第 2 步:加载另一个文档以替换文本。

IDocument replaceDocument = new Document("Document1.docx");

第 3 步:将指定文本替换为其他文档。

document.Replace("Document 1", replaceDocument, false, true);

第 4 步:保存文件。

document.SaveToFile("Output.docx", FileFormat.Docx2013);

输出

在 C# 中用 Word 文档替换文本

完整代码

using Spire.Doc;using Spire.Doc.Interface;namespace Replace_Text_With_Document{class Program{static void Main(string[] args){//Load a template documentDocument document = new Document("Template.docx");//Load another document to replace textIDocument replaceDocument = new Document("Document1.docx");//Replace specified text with the other documentdocument.Replace("Document 1", replaceDocument, false, true);//Save the filedocument.SaveToFile("Output.docx", FileFormat.Docx2013);}}}

以上便是如何在 C#、VB.NET 下检索 Word 中所有 TextRanges 的样式名称,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

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

上一篇 2022年8月12日
下一篇 2022年8月12日

相关推荐

发表回复

登录后才能评论