var word1 = new Document(@"C:\word1.docx");
var word2 = new Document(@"C:\word2.docx");
var importedSections = ImportSections(word1);
foreach (Section importedSection in importedSections)
{
MainDocument.Sections.Add(importedSection);
}
importedSections = ImportSections(word2);
foreach (Section importedSection in importedSections)
{
var mainDocumentLastSection = MainDocument.LastSection;
var importedSectionNodes = importedSection.Body.ChildNodes.ToArray();
foreach (var childNode in importedSectionNodes)
mainDocumentLastSection.Body.ChildNodes.Add(childNode);
}
ImportSections function:
public virtual Section[] ImportSections(Document pieceDocument)
{
var importFormatMode = ImportFormatMode.UseDestinationStyles;
var sectionCount = pieceDocument.Sections.Count;
var result = new Section[sectionCount];
var nodeImporter = new NodeImporter(pieceDocument, MainDocument, importFormatMode);
for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++)
{
var section = pieceDocument.Sections[sectionIndex];
var importedSection = (Section)nodeImporter.ImportNode(section, true);
importedSection.PageSetup.MultiplePages = section.PageSetup.MultiplePages;
result[sectionIndex] = importedSection;
}
return result;
}
Please help me solving this issue.
Thank you!