MergeDocs.vb
  1. ''
  2. '' This code is part of Document Solutions for Word demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports GrapeCity.Documents.Word
  7.  
  8. '' This sample shows how to merge two DOCX files into one.
  9. Public Class MergeDocs
  10. Public Function CreateDocx() As GcWordDocument
  11. Dim doc1 = New GcWordDocument()
  12. doc1.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx"))
  13.  
  14. Dim doc2 = New GcWordDocument()
  15. doc2.Load(Path.Combine("Resources", "WordDocs", "BuiltInStyles.docx"))
  16.  
  17. '' Static MergeDocuments() method overloads allow to merge any number of documents.
  18. '' Internally, those methods call the Body.CopyTo() method on each of the documents
  19. '' being merged, so the same results can be achieved using CopyTo().
  20. '' The different overloads allow to merge documents with full formatting,
  21. '' without formatting, Or using combinations of both.
  22. '' Here we demonstrate the most flexible MergeDocuments() overload by merging the
  23. '' two loaded documents twice, first copying their original formatting, And then
  24. '' clearing it
  25. Dim doc = GcWordDocument.MergeDocuments(
  26. (doc1, FormattingCopyStrategy.Copy),
  27. (doc2, FormattingCopyStrategy.Copy),
  28. (doc1, FormattingCopyStrategy.Clear),
  29. (doc2, FormattingCopyStrategy.Clear))
  30.  
  31. '' Done
  32. Return doc
  33. End Function
  34. End Class
  35.