We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail Merge Nested Region With Numbered List


The situation I have is the outer region is a table and two of its cells contain numbered lists. The numbered lists are additional regions.

New rows in the table are not resetting the numbering. If row 1 has items 1,2 and 3 then row 2 will contain 4,5,etc.

Is there some option I am missing in the MailMerge settings or in the docx template?
Failing that is there a way to fix this using a callback?

Thanks for any help you can provide.

Hi Kiel,

Thanks for your inquiry. It
would be great if you please share following details for testing
purposes. I will investigate the issue on my side and provide you more

create a simple application (for example a Console Application Project)
that helps us reproduce the same problem on our end and attach it here
for testing.
Please supply us with the input document that is causing the issue
Please supply us with the output document showing the undesired behavior
Please supply us with the expected document showing the desired behavior (You can create this document using Microsoft Word).

I couldn’t seem to log back in with that account so I had to create a new one. Must have typed a character in wrong somewhere when first registering.

I have created the files you asked for.


Hi Kiel,

Thanks for sharing the detail. I have logged a new Task in our issue tracking system as WORDSNET-9164 to investigate the shared issue. We will investigate your issue at our end and will post the results here for
your kind reference asap.

Thank you for your patience and understanding.

Hi Kiel,

Thanks for your patience. In your case, I suggest you please implement IFieldMergingCallback interface to achieve your requirements. Implement this interface if you want to control how data is inserted into merge fields during a mail merge operation.

Please use the following code snippet to achieve your requirements. Hope this helps you.

var dataSet = new DataSet();
var regionTable = new DataTable("Region");
var col2ListTable = new DataTable("Col2List");
dataSet.Relations.Add(regionTable.Columns[1], col2ListTable.Columns[0]);
for (var i = 0; i < 10; i++)
    regionTable.Rows.Add(i.ToString(), i.ToString(), i.ToString());
    for (var j = 0; j < 3; j++)
        col2ListTable.Rows.Add(i.ToString(), j.ToString());
var doc = new Aspose.Words.Document(MyDir + "template.docx");
doc.MailMerge.FieldMergingCallback = new HandleMergeTest30();
doc.Save(MyDir + "Out.docx");
private class HandleMergeTest30 : IFieldMergingCallback
    Cell currentCell;
    Aspose.Words.Lists.List list;
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
        if (e.TableName == "Col2List" && e.DocumentFieldName.Equals("Col2"))
            DocumentBuilder builder = new DocumentBuilder(e.Document);
            if (builder.CurrentNode.GetAncestor(NodeType.Cell) != currentCell)
                currentCell = (Cell)builder.CurrentNode.GetAncestor(NodeType.Cell);
                list = e.Document.Lists.Add(ListTemplate.NumberDefault);
                builder.CurrentParagraph.ListFormat.List = list;
                builder.CurrentParagraph.ListFormat.List = list;
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
        // Do nothing.

Worked perfectly. Thanks.

Hi Kiel,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.


I have the same probleam like above.
When I use attached code it works partly, but numeric list is added to every paragraph instead of only for number lists.

My problem is that I have mail merge with numeric list.
I have for example 3 sets of data and Aspose generate 3 pages, but numeric list is continued order. But in my opinion when using mail merge - each record should begin new totaly separated section with start new number list etc.

Hi Mateusz,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

Your input Word document.
Please attach the output Word file that shows the undesired behavior.
Please attach the expected output Word file that shows the desired behavior.
Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.