Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon May 22, 2023 11:13 am

Hello,
I'm using the following code to generate a Word document with a table using mail merge. The sample document is attached.
The file does get generated but no rows are added to the table. I'm running this in VS2022 and .NET 6.

Any advice will be appreciated.

Regards,

Waseem

Spire.Doc.Document doc = new Spire.Doc.Document();
doc.LoadFromFile("Sample_3.doc");

var Dt = new DataTable("Items");
Dt.Columns.Add("ItemNumber", typeof(string));
Dt.Columns.Add("ItemDescription", typeof(string));

Dt.Rows.Add("2.1", "title 1");
Dt.Rows.Add("2.2", "title 2");
Dt.Rows.Add("2.3", "title 3");

doc.MailMerge.ExecuteWidthRegion(Dt);
doc.SaveToFile("Result.docx", FileFormat.Docx2013);

waseemkhan
 
Posts: 1
Joined: Mon May 22, 2023 11:03 am

Tue May 23, 2023 7:55 am

Hello,

Thank you for your inquiry.
After investigation, we found that the issue was caused by incorrect naming of MailMergeField in the table of your Word document. After modifying the names of MailMergeField in the source file, the test result file is completely correct. Please refer to the attached input file (Sample_3.doc) and output file (Result.docx).
If you have any other questions or concerns, please feel free to contact us anytime.

Sincerely,
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Return to Spire.Doc

cron