MergeDocs.vb
''
'' This code is part of GrapeCity Documents for Word samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports GrapeCity.Documents.Word

'' This sample shows how to merge two DOCX files into one.
Public Class MergeDocs
    Public Function CreateDocx() As GcWordDocument
        Dim doc1 = New GcWordDocument()
        doc1.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx"))

        Dim 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
        Dim doc = GcWordDocument.MergeDocuments(
            (doc1, FormattingCopyStrategy.Copy),
            (doc2, FormattingCopyStrategy.Copy),
            (doc1, FormattingCopyStrategy.Clear),
            (doc2, FormattingCopyStrategy.Clear))

        '' Done
        Return doc
    End Function
End Class