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

Free Support Forum - aspose.com

Mail merge with nested tables is not working

I am using aspose.words.net dll for merge field operation . But for nested fields some how it is failing.
Could you please let me know the reason or if i am doing something wrong with my template. I am attaching the input,actualoutput,expected output documents. NestedMergeFieldsOutput.zip (35.0 KB)

@venkat2222,

You can get the expected output by using the following code:

DataSet ds = new DataSet();

DataTable dt1 = new DataTable();
dt1.TableName = "sortablesubform";
dt1.Columns.Add("ID", typeof(int));
dt1.Columns.Add("Something", typeof(string));
dt1.Rows.Add(1, "enddata1");
dt1.Rows.Add(2, "enddata2");
ds.Tables.Add(dt1);

DataTable dt2 = new DataTable();
dt2.TableName = "sortablesubformsub";
dt2.Columns.Add("sortablesubform_id", typeof(int));
dt2.Columns.Add("TextBox1", typeof(string));
dt2.Columns.Add("TextBox2", typeof(string));            

dt2.Rows.Add(1, "demo1", "demo2");
dt2.Rows.Add(1, "demo3", "demo4");
dt2.Rows.Add(2, "demo5", "demo6");
dt2.Rows.Add(2, "demo7", "demo8");

ds.Tables.Add(dt2);

DataColumn[] parentColumns = new DataColumn[] { ds.Tables[0].Columns["ID"] };
DataColumn[] childColumns = new DataColumn[] { ds.Tables[1].Columns["sortablesubform_id"] };
ds.Relations.Add(parentColumns, childColumns);

Document doc = new Document("E:\\NestedMergeFieldsOutput\\InputwordTemplate.docx");
doc.MailMerge.ExecuteWithRegions(ds);

doc.Save("E:\\NestedMergeFieldsOutput\\19.1.docx");