Join Multiple Documents Into A Single Document In .NET Applications


SUBMITTED BY: Guest

DATE: June 12, 2013, 1:13 a.m.

FORMAT: C#

SIZE: 2.2 kB

HITS: 844

  1. //Code for Joining Multiple Documents Together
  2. [C#]
  3. // The document that the other documents will be appended to.
  4. Document doc = new Document();
  5. // We should call this method to clear this document of any existing content.
  6. doc.RemoveAllChildren();
  7. int recordCount = 5;
  8. for (int i = 1; i <= recordCount; i++)
  9. {
  10. // Open the document to join.
  11. Document srcDoc = new Document(@"C:\DetailsList.doc");
  12. // Append the source document at the end of the destination document.
  13. doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
  14. // In automation you were required to insert a new section break at this point, however in Aspose.Words we
  15. // don't need to do anything here as the appended document is imported as separate sectons already.
  16. // If this is the second document or above being appended then unlink all headers footers in this section
  17. // from the headers and footers of the previous section.
  18. if (i > 1)
  19. doc.Sections[i].HeadersFooters.LinkToPrevious(false);
  20. }
  21. [VB.NET]
  22. ' The document that the other documents will be appended to.
  23. Dim doc As New Document()
  24. ' We should call this method to clear this document of any existing content.
  25. doc.RemoveAllChildren()
  26. Dim recordCount As Integer = 5
  27. For i As Integer = 1 To recordCount
  28. ' Open the document to join.
  29. Dim srcDoc As New Document("C:\DetailsList.doc")
  30. ' Append the source document at the end of the destination document.
  31. doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles)
  32. ' In automation you were required to insert a new section break at this point, however in Aspose.Words we
  33. ' don't need to do anything here as the appended document is imported as separate sectons already.
  34. ' If this is the second document or above being appended then unlink all headers footers in this section
  35. ' from the headers and footers of the previous section.
  36. If i > 1 Then
  37. doc.Sections(i).HeadersFooters.LinkToPrevious(False)
  38. End If
  39. Next i

comments powered by Disqus