Label Sample Code

Hi,

Could I have a source code in C# sample?

I have a datatable with data. Each record data is on a label and 2 labels per section.

For example:

John Smith
123 Polk Street
Isabelle Beaudoin
3443 Berri
Demetra Jolie
444 Hello Street
Thu Nguyen
23 Hanoi

I can use a word template or create on fly… as long I have the result.

Please give me the simple solution.

Thanks,
Tan Quan

Hi,

I’m using ASPOSE.Words component.
I’m looking forward to receive your response.

Hi

Thanks for your inquiry. I think the simplest way to achieve what you need is using Mail Merge with regions.
https://docs.aspose.com/words/net/types-of-mail-merge-operations/
I created simple example for you. Here is code:

//Create dummy datasource
DataTable table = new DataTable("Labels");
table.Columns.Add("Name");
table.Columns.Add("Address");
//Add few rows
table.Rows.Add(new object[] { "John Smith", "123 Polk Street" });
table.Rows.Add(new object[] { "Isabelle Beaudoin", "3443 Berri" });
table.Rows.Add(new object[] { "Demetra Jolie", "444 Hello Street" });
table.Rows.Add(new object[] { "Thu Nguyen", "23 Hanoi" });
//Open template
Document doc = new Document(@"Test012\in.doc");
//execute mail merge with regions
doc.MailMerge.ExecuteWithRegions(table);
//Save output document
doc.Save(@"Test012\out.doc");

Template and output document are attached.
I used the following structure of the template:

{ TableStart:Labels }{ Name }{ Address }|{NEXT}{ Name }{Address}{ TableEnd:Labels }
NEXT field is needed to move to the next record in the datasource. (You can press Alt+F9 to see field codes in the template)
Hope this helps.
Best regards.

It works.
Thank you.

Hi,
After testing with this template(see the attachment file) with the source code that you give me… The result are different and not I expected.
If there is a way to have the result as you mention below with this template.
Could you give me a new sample of source code so I can try?
I have try the source code that you give me a table and it work but not with this template (see the attachment file). What should I do to make it work?
Thanks,
Tan Quan

Hi

Thanks for your inquiry. You cannot use ExecuteWithRegions method with template you have attached, because there are no “regions” in your template (TableStart:myRegion and TableEnd:myRegion). So, Aspose.Words will not insert any data in your template if you use ExecuteWithRegions. In case of using Execute method, aspose.Words will insert data into your template, however it will generate separate section for each two records in your data source.
Why you do not use template like the one I have shown in my previous post?
I modified your template and now it should work.
Best regards.

Thank … work like a charm.

Hi,
I would be grateful if you could post again the sample doc you used for the labels example.
Thanks,
Eamonn

Hey,
I just seen it, sorry for this post.

where i can see the documents here

@pkbackupdme There are no attachments in this thread. Also, due to the security reasons attachments in the forum are accessible only by topic starter and Aspose staff.