Free Support Forum - aspose.com

Mail Merge With Static Content

Hi,

I am using Mail Merge Region for 2 tables in the word doc. Now I want to do one more Mail merge region. Please help me.

I had attched my template...

The «TableStart:T5»«Valu»«TableEnd:T5» should be displayed after the number of paragrah merged.

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

Thanks for your request. I think that you can just execute mail merge one more time. For example see the following code:

Document doc = new Document(@"Test182\in.doc");

doc.MailMerge.ExecuteWithRegions(t1);

doc.MailMerge.ExecuteWithRegions(t2);

doc.MailMerge.ExecuteWithRegions(t5);

doc.Save(@"Test182\out.doc");

Best regards.

Hi,

Thanks for the reply. I will explain my exact requriement.

I am having one template in word document and I merged the fields in the document.

For ex, If I have 3 records, Three paragraph will come. for each and every record I will get one paragraph continiously. At the end the document, ie) after 3 rd paragraph, I want to display my table details using merge.

If I am executing the code above, I am getting the merged records for each and every page. But I want to display it only at the end of the document. I attached my output for the above code.

Please help me.

doc.MailMerge.ExecuteWithRegions(Gettables2())
doc.MailMerge.ExecuteWithRegions(Gettables3())
doc.MailMerge.ExecuteWithRegions(Gettable(k))

Private Function Gettable(ByVal i As ArrayList) As DataTable

Dim dt As New DataTable
Dim dr As DataRow
Dim j As Integer

dt.TableName = "TBL"
dt.Columns.Add("Col")

For Each Val As String In i
dr = dt.NewRow()
Dim myControl1 As Control = FindControl("txt" & Val)
If Not myControl1 Is Nothing Then
Dim txtctrl As TextBox = myControl1
dt.Rows.Add(New Object() {txtctrl.Text})
End If
Next

Return dt

End Function


Private Function Gettables2() As DataTable

Dim dt As New DataTable
dt.TableName = "T1"
dt.Columns.Add("Y1")
dt.Columns.Add("R1")
'dt.Columns.Add("ID")


Dim dr As DataRow
dr = dt.NewRow()
dt.Rows.Add(New Object() {Textbox1.Text, Textbox3.Text})
dt.Rows.Add(New Object() {Textbox6.Text, Textbox4.Text})
dt.Rows.Add(New Object() {Textbox11.Text, Textbox5.Text})
dt.Rows.Add(New Object() {Textbox16.Text, Textbox7.Text})
dt.Rows.Add(New Object() {Textbox2.Text, Textbox8.Text})
Return dt

End Function

Private Function Gettables3() As DataTable

Dim dt As New DataTable
dt.TableName = "T2"
dt.Columns.Add("Y2")
dt.Columns.Add("R2")
'dt.Columns.Add("ID")

Dim dr As DataRow
dr = dt.NewRow()
dt.Rows.Add(New Object() {Textbox9.Text, Textbox10.Text})
dt.Rows.Add(New Object() {Textbox12.Text, Textbox13.Text})
dt.Rows.Add(New Object() {Textbox14.Text, Textbox15.Text})
dt.Rows.Add(New Object() {Textbox17.Text, Textbox18.Text})
dt.Rows.Add(New Object() {Textbox19.Text, Textbox20.Text})
Return dt

End Function

Regards,

Sujatha

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

Thanks for additional information. I think that you can try using two templates in this case. You can perform mail merge with the first template, then perform mail merge with the second template and then merge the result documents together.

Could you also please create a document using MS Word that will show me how the output document should looks like and attach this document here?

Best regards.