2017-03-03 67 views
0

我使用OPENXML如何使用OPENXML

這裏創建Word文檔形式的MemoryStream合併多個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文檔作爲一個單詞文件在MemoryStream或FileStream比保存它?

+0

你看過[OpenXmlPowerTools](https://github.com/OfficeDev/Open-Xml-PowerTools)嗎?有關[Eric White的網站]的更多信息(http://ericwhite.com/blog/blog/documentbuilder-developer-center/) – erdomke

回答

0

使用Open XML合併兩個文檔是一項相當艱鉅的任務。我建議你使用任何

  1. 埃裏克·懷特的OpenXmlPowerTools或
  2. 其中一個.NET庫,如Docentric工具包 OpenXmlPowerTools是免費的,能夠合併兩個文件,但你必須在合併過程中沒有控制。另一方面,Docentric Toolkit並不是免費的,但允許您控制合併過程的細節,例如如何樣式和部分合並,頁面編號如何重新啓動...