MailMerge with Regions - Two Line Detail

How can I set this table up correctly to merge properly?

I have attached a couple of screen shots to better explain what I need.

The table needs to have two rows for each year - the top row for the monthly wages, and the bottom row for the monthly service credits.

I tried wrapping the whole table in a region, then created two nested regions, one for each detail row. However, that ended up creating all the first line rows, then all the second line rows below them.

How do I set this up so that the two detail rows stay together? I cannot create a single, multiple line region because I get an error that says the table start and table end have to be on the same row.

Hi Charles,

Thanks for your inquiry. Please note that the mail merge region opening and closing tag (e.g. TableStart:Order, TableEnd:Order) both need to appear in the same row or cell. I suggest you please read following documentation links for your kind reference.
https://docs.aspose.com/words/java/nested-mail-merge-with-regions/
https://docs.aspose.com/words/net/nested-mail-merge-with-regions/

I have created a sample template which contains both TableStart:Order, TableEnd:Order at same row (the parent table contains a nested table at second row of second column). Please see the attached template for your kind reference.

Hope this helps you. Please let us know if you have any more queries.

DataTable table1 = new DataTable("table1");
table1.Columns.Add("Month1", typeof(string));
table1.Columns.Add("Month2", typeof(string));
table1.Rows.Add("Jan", "Feb");
DataTable Wages = new DataTable("Wages");
Wages.Columns.Add("Year", typeof(string));
Wages.Columns.Add("Wages", typeof(decimal));
Wages.Columns.Add("M1", typeof(decimal));
Wages.Columns.Add("M2", typeof(decimal));
Wages.Rows.Add("2012", 1000, 100, 200);
Wages.Rows.Add("2013", 1500, 50, 20);
DataTable Credit = new DataTable("Credit");
Credit.Columns.Add("Year", typeof(string));
Credit.Columns.Add("C1", typeof(decimal));
Credit.Columns.Add("C2", typeof(decimal));
Credit.Rows.Add("2012", 200, 300);
Credit.Rows.Add("2013", 250, 500);
DataSet ds = new DataSet();
ds.Tables.Add(table1);
ds.Tables.Add(Wages);
ds.Tables.Add(Credit);
ds.Relations.Add(new DataRelation("YeartoYear", Wages.Columns["Year"], Credit.Columns["Year"], false));
Document doc = new Document(MyDir + "MailMerge.docx");
doc.MailMerge.ExecuteWithRegions(ds);
doc.Save(MyDir + "out.docx");