...
Code Block |
---|
public void GenerateDocument() { //Select the state for which we will print out the data this.stateCode = "MA"; // Create WordTemplate WordTemplate wt = new WordTemplate(); // Open the template document string templatePath = @"..\..\WordTemplateFiles\MailMergeTemplate.docx"; wt.Open(templatePath); // Get the datatable for any state by parsing that state's specific csv file DataTable RegionData = GetCustomerData(@"..\..\WordData\MailMergeDemoData"+this.stateCode+".CSV"); // Set the DataTable as the source for the mailmerge. wt.SetMailMerge(RegionData); wt.Process(); // Save the document string docName = String.Format("MailMerge-{0}", this.stateCode); wt.Save(@"..\..\WordOutputFiles\"+ docName+ "_output"+".docx"); } |
\
Downloads
Panel |
---|
Template: MailMergeTemplate.docx Output: MailMerge-MA_output.docx |