List number not starting from 1 in a separate section

Hi Team,
I met the issue as title mentioned.
The code snippet is a simulation of the issue from our codebase. I can reproduce it on my side.

public static void main(String[] args) throws Exception {

    Document firstDoc = new Document("C:\\User\\report_to_add_Part I.docx");
    Document secondDoc = new Document("C:\\User\\report_to_add_Part II.docx");

    for (int i = 0; i < secondDoc.getSections().getCount(); i++) {
        // First need to import the section into the destination document,
        // this applies the destination lists and styles to the imported section
        Section sectionToImport =
                (Section) firstDoc.importNode(secondDoc.getSections().get(i), true, ImportFormatMode.USE_DESTINATION_STYLES);
        // Append the section to import to the last section
        firstDoc.getLastSection().appendContent(sectionToImport);
    }
    firstDoc.save("output.docx", SaveOptions.createSaveOptions(SaveFormat.DOCX));
}

report_to_add_Part I.docx (14.1 KB)

report_to_add_Part II.docx (13.8 KB)

Pls help check this issue. I’m using 22.2 with formal license, but I can reproduce on 25.2 with a trial. I also tried to use KEEP_SOURCE_FORMATTING import mode, not worked.

@windpine To get the expected output you should specify ImportFormatOptions.KeepSourceNumbering. Please see the following modified code:

Document firstDoc = new Document("C:\\Temp\\report_to_add_Part I.docx");
Document secondDoc = new Document("C:\\Temp\\report_to_add_Part II.docx");

ImportFormatOptions opt = new ImportFormatOptions();
opt.setKeepSourceNumbering(true);
NodeImporter importer = new NodeImporter(secondDoc, firstDoc, ImportFormatMode.USE_DESTINATION_STYLES, opt);

for (int i = 0; i < secondDoc.getSections().getCount(); i++)
{
    // First need to import the section into the destination document,
    // this applies the destination lists and styles to the imported section
    Section sectionToImport = (Section)importer.importNode(secondDoc.getSections().get(i), true);
    // Append the section to import to the last section
    firstDoc.getLastSection().appendContent(sectionToImport);
}
firstDoc.save("C:\\Temp\\out.docx");

out.docx (14.2 KB)

Thank you! It fixed now.

BTW, I want to know this KeepSourceNumbering option is a change in a version update, right? In my previous version of application, using Aspose 14.11, quite an old version, I don’t need to add this configuration and it worked at that time.

@windpine Yes, this option has been introduced in 19.4 version of Aspose.Words:
https://releases.aspose.com/words/java/release-notes/2019/aspose-words-for-java-19-4-release-notes/