Hi
Thanks for your request. I think that you can achieve this using MergeField event handler. For example see the following code and attached documents.
public void Test157()
{
string[] names = { "option1", "option2", "option3", "option4" };
//Row that contains empty data will be removed
string[] values = { "val1", "val2", "", "val4" };
//Open document
Document doc = new Document(@"Test157\in.doc");
//Add MergeField event handler
doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField157);
//Execute mail merge
doc.MailMerge.Execute(names, values);
//Save document
doc.Save(@"Test157\out.doc");
}
void MailMerge_MergeField157(object sender, MergeFieldEventArgs e)
{
//Check if value is empty
if (string.IsNullOrEmpty(e.FieldValue.ToString()))
{
//Get parent row
Node parantRow = e.Field.Start.GetAncestor(typeof(Row));
//Remove row
parantRow.Remove();
}
}
I hope this could help you.
Best regards.
Alexey Noskov
Developer/Technical Support
Aspose Auckland Team