Free Support Forum - aspose.com

New line insertion after table on node insertion

        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!

Here you have those two word documents from example:
Words.zip (19.2 KB)

@adrian.anton,

Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. There is empty paragraph at the end of document that end of section. You can remove it before joining documents as shown below. Hope this helps you.

If you still face problem, please ZIP and attach your expected output Word document here for our reference. We will then provide you more information about your query.

var word1 = new Document(MyDir + @"word1.docx");

if (word1.LastSection.Body.LastParagraph.ToString(SaveFormat.Text).Trim() == "")
    word1.LastSection.Body.LastParagraph.Remove();
var word2 = new Document(MyDir + @"word2.docx");