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

Free Support Forum - aspose.com

Re: regarding execultewithregion

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

Could you please attach the document? Also please attach the document that will show me what output is expected.

Best regards.

Here with i have attached a document contains both the template as well as a sample output

pls give a good suggestion

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

Thank you for additional information. As I told you earlier in this case you should use several templates. For example see the following code and attached documents.

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

Dim lic As License = New License()


'Create datasource for Services

'It will contains only names of Services

Dim services As DataTable = New DataTable("Services")


'Add few values to datasource

For i As Integer = 0 To 10

services.Rows.Add(New Object() {String.Format("Service_{0}", i)})


'Open main template

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

'Add MergeField event handler

AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeInsertSubdocument

'Execute mail merge


'Save output


End Sub

Private Sub HandleMergeInsertSubdocument(ByVal sender As Object, ByVal e As MergeFieldEventArgs)

'Check field name

If (e.FieldName = "Service") Then

'Create DocumentBuilder

Dim builder As DocumentBuilder = New DocumentBuilder(e.Document)

'Move DocumentBuilder cursor to field

builder.MoveToField(e.Field, True)

'Open another template

Dim subdoc As Document = New Document("subdoc.doc")

'Get data for mail merge

Dim ds As DataSet = New DataSet()

Dim t1 As DataTable = GetTable(1)

Dim t2 As DataTable = GetTable(2)



'Execute mail merge


'Insert subdocument into main document

InsertDocument(builder.CurrentParagraph, subdoc)

End If

End Sub

Private Function GetTable(ByVal index As Integer) As DataTable

'Create table

Dim table As DataTable = New DataTable("T" + index.ToString())

table.Columns.Add("Y" + index.ToString())

table.Columns.Add("R" + index.ToString())

'Add some data

For i As Integer = 0 To 3

table.Rows.Add(New Object() {i.ToString(), index.ToString()})


Return table

End Function

You can find InsertDocument method here:


I hope this could help you.

Best regards.