Message-ID: <1401260638.8279.1711639791162.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8278_12477371.1711639791162" ------=_Part_8278_12477371.1711639791162 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Merge Documents

Merge Documents

Intro

WordWriter allows you to = insert elements from separate documents. You can use this functionality to = copy/paste document elements into different files, or to easily merge Word = documents. This sample demonstrates how to merge three different Word docum= ents into one unified document.


This sample uses the WordApplication class to open three existing= documents and insert them into a new blank document. The InsertBefore() an= d InsertAfter() methods are used, which accept an element from the current = document or any other document, inserting it into the current document.

Code

=20
 public void GenerateDocument()
{
 // Initialize the WordApplication and create a blank document. 
 WordApplication app =3D new WordApplication();

 Document doc =3D app.Create();

 // Open first document to merge 
 Document doc1 =3D app.Open(@"..\..\WordTemplateFiles\mergedocuments1.=
doc");

 // Append first document 
 doc.Append(doc1);

 // Open second document to merge 
 Document doc2 =3D app.Open(@"..\..\WordTemplateFiles\mergedocuments2.=
doc");

 // Append second document  
 doc.Append(doc2);

 // Open third document to merge 
 Document doc3 =3D app.Open(@"..\..\WordTemplateFiles\mergedocuments3.=
doc");

 // Append third document 
 doc.Append(doc3);

 // Save the merged document 
 app.Save(doc, @"..\..\WordOutputFiles\MergedDocument_out.doc");
}

=20

Download

Files to be Merged:

Output File: Mer= gedDocument_out.doc

------=_Part_8278_12477371.1711639791162--