The Syncfusion .NET Word Library (DocIO) provides powerful and comprehensive APIs to merge multiple Word documents into a single document. With just a few lines of code, you can streamline the process without relying on Microsoft Word or interop dependencies.
This example code shows how to merge Word documents using the Syncfusion .NET Word Library with just few lines of code in C#.
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
//Open source document stream
using (FileStream sourceStream = new FileStream("SourceDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Load source Word document
using (WordDocument sourceDocument = new WordDocument(sourceStream, FormatType.Automatic))
{
//Open destination document stream
using (FileStream destinationStream = new FileStream("DestinationDocument.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Load destination Word document
using (WordDocument destinationDocument = new WordDocument(destinationStream, FormatType.Docx))
{
//Import the contents of the source document at the end of the destination document
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
//Create output file stream
using (FileStream outputFileStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite))
{
// Save the Word document to the output file stream
destinationDocument.Save(outputFileStream, FormatType.Docx);
}
}
}
}
}
Merges the contents from multiple Word documents, retaining the original formatting in the merged document.
Merges the contents from Word documents and applies the formatting of one of them, designated the destination document.
Merges the contents from Word documents and either restarts or continues the list numbering.
Merges only the text from multiple Word documents without keeping the formatting, headers, or footers.
Discover resources from our knowledge base that enhance your efficiency in merging Word documents in C#:
Knowledge base
Knowledge base
Knowledge base
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
Word file formats such as DOC, DOT, DOCX, DOTX, DOCM, DOTM, as well as Word Processing 2007 XML, Word 2003 XML Document, and other formats such as HTML, text, and Markdown are supported.
Yes, you can merge specific sections from multiple Word documents into a single Word document.
Yes, you can merge multiple Word documents and save the merged document as a PDF, images, or HTML using the .NET Word Library.
Yes, you can automate the merging of a batch of Word documents in C# using the .NET Word Library.
Yes, you can merge documents with various options such as retaining source formatting, applying destination styles and merging text only.
You can access it through the Syncfusion.DocIO.Net.Core NuGet package. Detailed code samples are available in the documentation.
Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.