Thanks for your inquiry. In your case, I suggest you please pass DataTable or DataSet to MailMerge.ExecuteWithRegions method. Please check the overloaded method of MailMerge.ExecuteWithRegions from here:
Please read following documentation link for your kind reference.
Please check the mail merge with regions code example in Aspose.Words for .NET examples repository at GitHub and let us know if you have any more queries.
for your inquiry. If you want to remove the unused fields, empty
paragraphs, unused regions etc during mail merge process, please use the
MailMerge.CleanupOptions property. Following code snippet shows how to
instruct the mail merge engine to remove any empty paragraphs and unused regions.
doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions;
//doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedFields;
//doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveContainingFields;
doc.Save(MyDir + @"Out.doc");
Moreover, you can also delete certain fields from the document by implementing IFieldMergingCallback interface as shown in following code example. Please check the following code example for your kind reference.
Hope this helps you. Please let us know if you have any more queries.
var doc = new Aspose.Words.Document(MyDir + "in.docx");
doc.MailMerge.FieldMergingCallback = new HandleMergeTest31();
doc.Save(MyDir + "Out.docx");
private class HandleMergeTest31 : IFieldMergingCallback
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
if (e.TableName == "TableName" && e.DocumentFieldName.Equals("FieldName"))
if (e.FieldValue.ToString().Trim() == "")e.Field.Remove();
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
// Do nothing.
Thank you very much!
for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.