Hi,
I was trying to print labels using the aspose words i got the latest dlls i.e 9.7. I could easily print one address label using the mail merge. But when i wanted to print multiple addresses on a single page its unable to print the addresses. When i use doc.mailmerge.execute method it prints only the first address where as when i use doc.mailmerge.executewithregions method it doesn’t print anything but just shows the doc itself. I’m attaching the test document and also pasting the code i had used to do label printing.
Dim objInStream As stream
Dim objOutStream As stream
Dim dtLabelTable As datatable = New Datatable()
Try
dtLabelTable.Columns.Add("fname")
dtLabelTable.Columns.Add("lname")
dtLabelTable.Columns.Add("address")
dtLabelTable.Columns.Add("city")
dtLabelTable.columns.add("state")
dtLabelTable.columns.add("zip")
' Add some data
dtLabelTable.Rows.Add(New Object() {"Smith", "John", "xyz street", "Newyork", "NewYork", "88890"})
dtLabelTable.Rows.Add(New Object() {"Graham", "Smith", "xyz street", "Newyork", "NewYork", "88890"})
'' Instantiate the License class
Dim lic As Aspose.Words.License = New Aspose.Words.License()
lic.SetLicense("Aspose.Total.lic")
Catch ex As Exception
End Try
'open template
Dim doc As Document = New Document(Directory.GetCurrentDirectory + "\test1.doc")
'execute the mail merge
doc.MailMerge.ExecuteWithRegions(dtLabelTable)
'save the document to the memory stream
doc.Save(Directory.GetCurrentDirectory + "\output.doc")
doc.Save(objInStream, SaveFormat.Pdf)
objOutStream = objInStream
I would really appreciate your help on this.
Regards,
Ram.
Thanks for your request. To execute mail merge with regions there should be special merge fields with names TableStart:MyRegion and TableEnd:MyRegion, where MyRegion name of the region.
Please see the attached template and the following code:
/// Open template.
Document doc = new Document("test1.doc");
DataTable dtLabelTable = new DataTable("Test1");
dtLabelTable.Columns.Add("fname");
dtLabelTable.Columns.Add("lname");
dtLabelTable.Columns.Add("address");
dtLabelTable.Columns.Add("city");
dtLabelTable.Columns.Add("state");
dtLabelTable.Columns.Add("zip");
// Add some data
dtLabelTable.Rows.Add(new object[]
{
"Smith",
"John",
"xyz street",
"Newyork",
"NewYork",
"88890"
});
dtLabelTable.Rows.Add(new object[]
{
"Graham",
"Smith",
"xyz street",
"Newyork",
"NewYork",
"88890"
});
doc.MailMerge.ExecuteWithRegions(dtLabelTable);
doc.Save("out.doc");
Hello, thanks for your additional information.
I also tried using the code proposed by my colleague and I have just all works without problems. Could you please attach your test project. I’ll see and correct the code if it needed.
All that i’m using is the code which i had posted in my earlier post and those docs which i used as templates. Anways will give it one more shot and would let you know.
Thanks for your replies.
Hello
Thanks for your request. It seems your code is incorrect. Please try using my code:
Dim doc As New Document("test1.doc")
Dim dtLabelTable As New DataTable("Test1")
dtLabelTable.Columns.Add("fname")
dtLabelTable.Columns.Add("lname")
dtLabelTable.Columns.Add("address")
dtLabelTable.Columns.Add("city")
dtLabelTable.Columns.Add("state")
dtLabelTable.Columns.Add("zip")
'Add some data
dtLabelTable.Rows.Add(New Object() {"Smith", "John", "xyz street", "Newyork", "NewYork", "88890"})
dtLabelTable.Rows.Add(New Object() {"Graham", "Smith", "xyz street", "Newyork", "NewYork", "88890"})
doc.MailMerge.ExecuteWithRegions(dtLabelTable)
doc.Save("out.doc")