Hi
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
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 Main()
Dim lic As License = New License()
lic.SetLicense("Aspose.Words.lic")
'Create datasource for Services
'It will contains only names of Services
Dim services As DataTable = New DataTable("Services")
services.Columns.Add("Service")
'Add few values to datasource
For i As Integer = 0 To 10
services.Rows.Add(New Object() {String.Format("Service_{0}", i)})
Next
'Open main template
Dim doc As Document = New Document("in.doc")
'Add MergeField event handler
AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeInsertSubdocument
'Execute mail merge
doc.MailMerge.ExecuteWithRegions(services)
'Save output
doc.Save("out.doc")
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)
ds.Tables.Add(t1)
ds.Tables.Add(t2)
'Execute mail merge
subdoc.MailMerge.ExecuteWithRegions(ds)
'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()})
Next
Return table
End Function
You can find InsertDocument method here:
https://docs.aspose.com/words/java/insert-and-append-documents/
I hope this could help you.
Best regards.