MergeDocs.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Linq;
  9. using GrapeCity.Documents.Word;
  10.  
  11. namespace DsWordWeb.Demos
  12. {
  13. // This sample shows how to merge two DOCX files into one.
  14. public class MergeDocs
  15. {
  16. public GcWordDocument CreateDocx()
  17. {
  18. var doc1 = new GcWordDocument();
  19. doc1.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx"));
  20.  
  21. var doc2 = new GcWordDocument();
  22. doc2.Load(Path.Combine("Resources", "WordDocs", "BuiltInStyles.docx"));
  23.  
  24. // Static MergeDocuments() method overloads allow to merge any number of documents.
  25. // Internally, those methods call the Body.CopyTo() method on each of the documents
  26. // being merged, so the same results can be achieved using CopyTo().
  27. // The different overloads allow to merge documents with full formatting,
  28. // without formatting, or using combinations of both.
  29. // Here we demonstrate the most flexible MergeDocuments() overload by merging the
  30. // two loaded documents twice, first copying their original formatting, and then
  31. // clearing it:
  32. var doc = GcWordDocument.MergeDocuments(
  33. (doc1, FormattingCopyStrategy.Copy),
  34. (doc2, FormattingCopyStrategy.Copy),
  35. (doc1, FormattingCopyStrategy.Clear),
  36. (doc2, FormattingCopyStrategy.Clear));
  37.  
  38. // Done:
  39. return doc;
  40. }
  41. }
  42. }
  43.