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

Free Support Forum - aspose.com

Mail Merge Regions

Dear Sir / Madam,

I have an appointment letter formation in mail merge aspose. Based on some conditions which are string conditions few paragraphs will be seen otherwise not. For E.g If I belong to Senior Management Grade then I am going to be benefit with few Allowances which are mentioned in points. If I dont belong to Senior Management Grade I should not see that points at all. How can i check for String conditions in aspose.

Can any one help in solving my problem.

It is urgent.....

Eagerly waiting for reply

Thanks & Regards


This message was posted using Page2Forum from Mail Merge with Regions Explained - Aspose.Words for .NET and Java

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think that you can achieve this using MergeField event handler. For example see the following code:

public void Test()


//Open template

Document doc = new Document("in.doc");

//Add MergeField event handler

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);

//Execute mail merge


//Save output document



void MailMerge_MergeField(object sender, MergeFieldEventArgs e)


if (e.FieldName == "myField")


//Here you can insert your condition logic

//and do something with document



Also see the following links for more information.



Best regards.

Thanks for the help. But as i am new to aspose i am bit finding it diffiicult to handle the previous code. Can u send me some more links or sample code to use the Regions with aspose mail merge.

Even i request you to send me the code in vb.net as i am into asp.net development not C# i am not having much idea.

Waiting for the reply.

Thanks & Regards


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Here is code example how you can perform mail merge with regions and use MergeField event handler. Also see attached template.

Dim mCurrentName As String

Sub <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Main()

Dim lic As Aspose.Words.License = New Aspose.Words.License()


Dim table As New DataTable("MyTable")







Dim noRep As Integer = 0

For i As Integer = 0 To 4

noRep = i

table.Rows.Add(New Object() {"Alexey" & i.ToString(), "Option1", "Option2", "Option3", "Option4", "Option5"})


'Open template document

Dim doc As New Document("in.doc")

'Add MergeField event handler

AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeField

'Execute mail merge with regions


'Save output document


End Sub

Sub HandleMergeField(ByVal sender As Object, ByVal e As Aspose.Words.Reporting.MergeFieldEventArgs)

'Here you can place your conditional logic

If (e.FieldName = "Name") Then

mCurrentName = e.FieldValue


If (e.FieldName = "Option1" And mCurrentName = "Alexey0") Then

e.Field.Remove() 'dont show Option1 if name is Alexey0

End If

End If

End Sub

Also see the following links.



Best regards.