Hi
I never catch the event with ExecuteWithRegions(DataTable dte) method.
Thanks
Hi
Thanks for your request. Could you please attach your template and provide me your code for testing? I will check the issue on my side and provide you more information.
Best regards.
I can’t give you some code because, It’s a big module with a lot of code.
But I have follow the link :
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
Please make sure that MergeFieldEventHandler is called in ExecuteWithRegions(DataTable) method.
Thanks
Hi
Thank you for additional information. I used the following code for testing and all works fine on my side:
// Create dummy datasource
DataTable dt = new DataTable("MyTable");
dt.Columns.Add("col1");
dt.Columns.Add("col2");
for (int i = 0; i <10; i++)
dt.Rows.Add(new object[]
{
"val1",
"val2"
});
// Open template
Document doc = new Document(@"Test001\in.doc");
// Add MergeField event handler
doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);
// execute mail merge with regions
doc.MailMerge.ExecuteWithRegions(dt);
// Save output doc.
doc.Save(@"Test001\out.doc");
void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
{
// Do something in MergeField event
if (e.FieldName == "col1" || e.FieldName == "col2")
e.Text = "this text was writen from MergeField event";
}
Best regards.
Can you give me your file “in.doc” ?
Hi
Thanks for your request. The input document is very simple. I attached both input and output documents.
Best regards.