Hello Syncfusion,
I'm not sure if I'm doing this all wrong or not but figured I'd ask. I have a word document that I have put a bunch of merge fields in, this is to print a sheet of labels. I run the code below and it just spits out the word document just showing the merge fields but not actually inserting the data from my list.
FileStream fileStreamPath = new FileStream($"{ webHostEnv.WebRootPath }\\Avery5160DevLabels.doc", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument wordDocument = new WordDocument(fileStreamPath, FormatType.Docx);
//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection
MailMergeDataTable mailingData = new MailMergeDataTable("Members", membersList);
//Performs Mail merge
wordDocument.MailMerge.ExecuteGroup(mailingData);
//Download Word document in the browser
using (MemoryStream stream = new MemoryStream())
{
//Saves the Word document to MemoryStream
wordDocument.Save(stream, FormatType.Docx);
wordDocument.Close();
stream.Position = 0;
//Download Word document in the browser
return stream;
}
I've looked at the guide but can't seem to get it to work as described.
Thanks,
Andrew
Thanks for the reply, I was finishing up another part of my program and took a look at this tonight. I had this linked to a table in my database but also unlinked it but neither worked. I am running Syncfusion version 19.4.0.56. This is what it looks like when I run the merge and download the document:
Hi Andrew,
On further analyzing the given input Word document, TableStart and TableEnd
(region of group) are not specified in correct format. So, fields are not updated properly.
We have modified the input document and prepared the sample application as per
your requirement.
In the input Word document, we have done the following changes:
Inserted BeginGroup or TableStart before the table.
Inserted EndGroup or TableEnd end of the table.
Please refer to the below link.
https://help.syncfusion.com/file-formats/docio/mail-merge/mail-merge-for-group#create-template-for-group-mail-merge
Please find the sample and input Word document from the below attachment:
In the above sample, we have done the following things:
Open the word document
Gets the member details
Perform the mail merge
Saves the word document
Please find the below links to
know more about mail merge
https://help.syncfusion.com/file-formats/docio/working-with-mail-merge
https://help.syncfusion.com/file-formats/docio/mail-merge/mail-merge-for-group
https://help.syncfusion.com/file-formats/docio/mail-merge/mail-merge-events
https://github.com/SyncfusionExamples/Mail-Merge-Examples
Regards,
Lokesh B
Thanks for getting back to me. So it works if I use your template but when I change my tableName fields to the Begin/End Group like yours has, it doesn't work. I'm downloading a template from Avery and then linking it to my database, putting the merge fields in and then setting it back to normal word doc. Not sure if this is the reason or not but what process did you use to make your template?
Thanks
Hi Andrew,
We have modified your given input Word document at our end. In the modified input Word document, we have done the following things.
1. We have removed the shapes from the Word document.
2. We have removed TableEnd from the first cell and added that TableEnd in the last cell.
Please find the input Word document in the below attachment.
Could you please try this Word
document at your end and provide us confirmation of whether the problem has been resolved or not.
If you still facing issue means, we suspect that the reported
issue might be due to field values given to the Word document during the mail merge
process. So, could you please share with us the modified sample (Field values and
code snippet) to reproduce the same issue which you mentioned.
This will be more helpful to reproduce the same issue on our end. Thereby, we
will proceed further on the reported issue and provide you with the appropriate
solution at the earliest.
Regards,
Lokesh B