Merging Word DOCX Documents and Continue List Numbering using C# .NET

I am trying to merge 2 documents but could not get the list numbering to continue no matter what option i tried. I am following the example from ImportFormatOptions.KeepSourceNumbering | Aspose.Words for .NET and set KeepSourceNumbering = false.

Please see the sample docs here TestList.zip (20.4 KB)

@eric12ten,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-22103. We will further look into the details of this problem and will keep you updated here on the status of the linked issue. We apologize for any inconvenience.

A post was split to a new topic: Merge Two Word Documents & Continue List Numbering (C# .NET)

The issues you have found earlier (filed as WORDSNET-22103) have been fixed in this Aspose.Words for .NET 21.6 update and this Aspose.Words for Java 21.6 update.

@eric12ten,

Regarding WORDSNET-22103, it is to inform you that we have introduced the following new public property into the ImportFormatOptions class:

The following use-case explains how to merge pasted lists with surrounding lists when adding one document to another:

Document srcDoc = new Document("C:\\TestList\\TestList1.docx");
Document dstDoc = new Document("C:\\TestList\\TestList.docx");
srcDoc.LastSection.PageSetup.LineNumberRestartMode = LineNumberRestartMode.Continuous;
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.MergePastedLists = true;
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles, importFormatOptions);
dstDoc.Save("C:\\TestList\\21.6 MergePastedLists true.docx");

@awais.hafeez,

This still don’t work with the new option. I need it to work with NodeImporter per ImportFormatOptions.KeepSourceNumbering | Aspose.Words for .NET, not the AppendDocument snippet that you have given

@eric12ten,

To continue numbering, you can simply assign the same list to the imported Paragraphs. Please check if the following code is acceptable for you?

Document srcDoc = new Document("C:\\temp\\TestList\\TestList1.docx");
Document dstDoc = new Document("C:\\temp\\TestList\\TestList.docx");

NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.UseDestinationStyles);
foreach (Paragraph paragraph in srcDoc.FirstSection.Body.Paragraphs)
{
    Node importedNode = importer.ImportNode(paragraph, true);
    dstDoc.LastSection.Body.AppendChild(importedNode);
}

Paragraph firstParagraph = dstDoc.FirstSection.Body.FirstParagraph;
Paragraph item = dstDoc.FirstSection.Body.Paragraphs[3];
while (item.IsListItem)
{
    item.ListFormat.List = firstParagraph.ListFormat.List;
    item = item.NextSibling as Paragraph;
    if (item == null)
        break;
}

dstDoc.Save("C:\\temp\\TestList\\output word.docx");