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


    Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。下面我们将给您介绍如何在 C#、VB.NET 下检索 Word 中所有 TextRanges 的样式名称

    Spire.Doc for.NET 最新下载(qun:767755948)icon-default.png?t=M85Bhttps://www.evget.com/product/3368/download

    Spire.Doc 提供了几个重载的 Replace 方法来替换不同场景中的文本。本文将向您展示如何使用 Spire.Doc 将模板文档中的指定文本替换为另一个文档。

    模板文件:

    替换文本的文档:

    详细步骤:

    第 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);

    输出

    完整代码

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

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

  • 相关阅读:
    pmp考试是什么?
    拥抱 Spring 全新 OAuth 解决方案
    前端 JS 实现图片元素转 BASE64 编码
    PHP常见算法
    ConcurrentHashMap的transfer阅读
    编译原理实验二、 编译器认知实验报告
    Web3D虚拟人捏脸
    车载系统的 加减串器应用示意
    windows server安装mysql后公司区域网连接
    Loss模块
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/127901849