A merge field for an incremental number in a table without needing to make code changes

Hi,

Is there an out of the box merge field for an incremental number, for a table with a tablestart and tableend.

A customer of ours wants to add an incremental number to the table, with the number increasing by 1 on each row of the table. I know we can do this in code, and send a new field through with an incremental number, but I was wondering if there was a built in merge field that did this, without the need for code changes.

Many thanks,

Trevor

@trevor.sharp You can easily achieve this by using list in your template. For example see the attached template and output produced by the following code:

DataTable dt = new DataTable("Data");
dt.Columns.Add("Col1");
dt.Columns.Add("Col2");
dt.Columns.Add("Col3");

for (int i = 0; i < 10; i++)
    dt.Rows.Add($"col1_{i}", $"col2_{i}", $"col3_{i}");

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.ExecuteWithRegions(dt);
doc.Save(@"C:\Temp\out.docx");

in.docx (14.3 KB)
out.docx (11.8 KB)

Alternative you can use SEQ field in the template:
in_seq.docx (14.3 KB)
out_seq.docx (11.9 KB)

Brilliant, thanks Alexey, we will give this a go.

Thanks for your help on this.

Have a good weekend.

Trevor

1 Like