簡體   English   中英

如何使用openxml合並多個Word文檔形式MemoryStream

[英]how to merge multiple word document form MemoryStream using openxml

我使用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文檔合並為一個WordDocument在MemoryStream或FileStream中而不保存呢?

使用Open XML合並兩個文檔是一項艱巨的任務。 我建議您使用

  1. 埃里克·懷特(Eric White)的OpenXmlPowerTools或
  2. .NET庫之一(例如Docentric Toolkit OpenXmlPowerTools)是免費的,並且能夠合並兩個文檔,但是您無法控制合並過程。 另一方面,Docentric Toolkit不是免費的,但允許您將合並過程控制得非常詳細,例如,樣式和節如何合並,頁碼如何重新啟動...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM