MergeDocs.cs
C# VB
//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.IO;using GrapeCity.Documents.Word;
namespace DsWordWeb.Demos{ // This sample shows how to merge two DOCX files into one. public class MergeDocs { public GcWordDocument CreateDocx() { var doc1 = new GcWordDocument(); doc1.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx"));
var doc2 = new GcWordDocument(); doc2.Load(Path.Combine("Resources", "WordDocs", "BuiltInStyles.docx"));
// Static MergeDocuments() method overloads allow to merge any number of documents. // Internally, those methods call the Body.CopyTo() method on each of the documents // being merged, so the same results can be achieved using CopyTo(). // The different overloads allow to merge documents with full formatting, // without formatting, or using combinations of both. // Here we demonstrate the most flexible MergeDocuments() overload by merging the // two loaded documents twice, first copying their original formatting, and then // clearing it: var doc = GcWordDocument.MergeDocuments( (doc1, FormattingCopyStrategy.Copy), (doc2, FormattingCopyStrategy.Copy), (doc1, FormattingCopyStrategy.Clear), (doc2, FormattingCopyStrategy.Clear));
// Done: return doc; } }}