Message-ID: <985799760.9381.1711689829860.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9380_434615201.1711689829860" ------=_Part_9380_434615201.1711689829860 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Purchase Order Demo

Purchase Order Demo

Intro

A generic purchase ord= er document with a header section and an expanding Word table for detail ro= ws.


This demo uses the setDataSource and = setRepeatBlock methods together.  The SetDataSource method i= s used to assign all of the single-value items to the order header and tota= l sections.  A repeat block is defined in the template document around= one table row so that the table will automatically expand for every row of= data in the order detail query.

Code

=20
   public void GenerateDocument()
        {
            // Creat=
e an instance of WordTemplate
            WordTemp=
late wt =3D new WordTemplate();
 
            // Open =
the template document
            string t=
emplatePath =3D @"..\..\WordTemplateFiles\PurchaseOrderTemplate.docx&q=
uot;;
            wt.Open(=
templatePath);
 
            // Query=
 the database for header and detail information.
            // Set t=
hese DataTables as WordTemplate data sources.
           
            DataTabl=
e dtHeader =3D GetOrderHeaderData(@"..\..\WordData\PurchaseOrderDemoHe=
aderData.csv");
            DataTabl=
e dtDetail =3D GetOrderDetailData(@"..\..\WordData\PurchaseOrderDemoDe=
tailData.csv");
            wt.SetDa=
taSource(dtHeader);
            wt.SetRe=
peatBlock(dtDetail, "OrderDetailQuery");
            wt.Proce=
ss();
 
            // Save =
the document to the disc
            wt.Save(=
@"..\..\WordOutputFiles\PurchaseOrder_output.docx");
        }

        /// <summary>Retrieve a DataTable of orde=
r header data</summary>
        /// <param name=3D"orderId">Ord=
erID for which to retrieve data</param>
        /// <returns>DataTable of the requested o=
rder's data</returns>
        private DataTable GetOrderHeaderData(String csv=
FileName)
        {
            DataTable dt; 
            using (GenericParserAdapter parse=
r =3D new GenericParserAdapter(csvFileName))
            {
                parser.ColumnDelimi=
ter =3D ',';
                parser.FirstRowHasH=
eader =3D true;

                dt =3D parser.GetDa=
taTable();
            }


            return dt;
        }

        /// <summary>Retrieve a ReusltSet of orde=
r detail line items</summary>
        /// <param name=3D"orderId">Ord=
erID for which to retrieve data</param>
        /// <returns>DataTable of the requested o=
rder's line items</returns>
        private DataTable GetOrderDetailData(String csv=
FileName)
        {
            DataTable dt;
            using (GenericParserAdapter parse=
r =3D new GenericParserAdapter(csvFileName))
            {
                parser.ColumnDelimi=
ter =3D ',';
                parser.FirstRowHasH=
eader =3D true;

                dt =3D parser.GetDa=
taTable();
            }


            return dt; 
        }

=20

 Downloads

------=_Part_9380_434615201.1711689829860--