Sometimes, people would like to merge two or more Word documents into one because these documents are talking about one topic or each of them is one part of article or story. Generally speaking, contents in documents will not be influenced after merging. It means that the contents will be the same as the original documents. But before merging, we should pay attention to merging order.
In this post, I will share an easy method to merge Word with C#/VB.NET.
In my example, I prepare two documents. One is overview of New Zealand and the other is New Zealand history. I need to merge the two into one and the contents in first documents will be put on front of history.
Note: a .NET Word component, Spire.Doc for .NET is used in this method, so I have added its dll file as reference in my project at the beginning.
- Load document Introduction and History from computer.
- Merge two documents by using for each sentence. Get sections in document History and then add these sections to document Introduction.
- Save and launch file.
static void Main(string args)
//Load Document1 and Document2
Document document = new Document();
Document document2 = new Document();
foreach(Section sec in document2.Sections)
//Save and Launch
Friend Class Merge
Shared Sub Main(ByVal args() AsString)
Dim document AsNew Document()
Dim document2 AsNew Document()
For Each sec As Section In document2.Sections
‘Save and Launch
Result Shown as Following: