【问题标题】:how to merge multiple word document form MemoryStream using openxml如何使用openxml合并多个word文档表单MemoryStream
【发布时间】:2017-03-03 01:24:42
【问题描述】:

我使用 openxml 创建 Word 文档表单 MemoryStream

这是我正在使用的代码:

 System.IO.MemoryStream ms1=new MemoryStream();
 using (var mainDoc = WordprocessingDocument.Create(ms1, WordprocessingDocumentType.Document))
 {
    mainDoc.AddMainDocumentPart();
    mainDoc.MainDocumentPart.Document =
                new Document(new Body(new Paragraph(new Run(new Text("Hello World 1!")))));
                mainDoc.MainDocumentPart.Document.Save();
 }

 System.IO.MemoryStream ms2 = new MemoryStream();
 using (var mainDoc = WordprocessingDocument.Create(ms2,WordprocessingDocumentType.Document))
 {
                mainDoc.AddMainDocumentPart();
                mainDoc.MainDocumentPart.Document =
                new Document(new Body(new Paragraph(new Run(new Text("Hello World 2!")))));
                mainDoc.MainDocumentPart.Document.Save();
  }

我可以将一个 MemoryStream 保存到 FileStream 中,然后保存到 .docx 文件中 打开它,但是如何将两个 MemoryStream word 文档合并为 MemoryStream 或 FileStream 中的一个 word 文档而不是保存它?

【问题讨论】:

标签: c# openxml


【解决方案1】:

使用 Open XML 合并两个文档是一项艰巨的任务。我建议你使用任何一个

  1. Eric White 的 OpenXmlPowerTools 或
  2. .NET 库之一,例如 Docentric Toolkit OpenXmlPowerTools 是免费的,能够合并两个文档,但您无法控制合并过程。另一方面,Docentric Toolkit 不是免费的,但允许您控制合并过程的详细信息,例如样式和部分如何合并,页码如何重新开始...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多