Message-ID: <535216968.8581.1711650823240.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8580_1589530064.1711650823240" ------=_Part_8580_1589530064.1711650823240 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Letters will be created for a selection of customers in the datab=
ase. This demo uses Nested Repeat Blocksthat signal Wor=
dTemplate to only repeat specific sections of the document when appropriate=
. This way we can create complex documents with dynamically generated table=
s with only a single database query and one call to SetRepeatBlock=
.
Note that using nested repeat blocks is only supported by using docx fil= es.
public void GenerateDocument() { WordTemplate wt =3D new WordTemplate(); wt.Open(@"..\..\WordTemplateFiles\NestedMailMergeTemplate.= docx"); //Retrieve the Data from the source, a csv file with a helper m= ethod DataTable dt =3D GetMailMergeData(@"..\..\WordData\NestedM= ailMergeData.csv"); // set dt as the datasource for the repeatblock and "MailM= erge" as the bookmark. // this will cause wordwriter to bind each letter on a differen= t page of the output file. wt.SetRepeatBlock(dt, "MailMerge"); wt.Process(); //Save the Document in the desired location wt.Save(@"..\..\WordOutputFiles\NestedMailMerge_output.doc= x"); } //Helper method to parse the csv files with data private DataTable GetMailMergeData(string csvFileName) { DataTable dt =3D new DataTable(); using (GenericParserAdapter parser =3D new GenericParserAdapter= (csvFileName)) { parser.ColumnDelimiter =3D ','; parser.FirstRowHasHeader =3D true; dt =3D parser.GetDataTable(); } return dt; } }=20
Template: NestedMailMergeTemplate.docx
Data: NestedMailMergeData.csv
Output: NestedMailMerge_output.docx
=20