Intro

A generic purchase order document with a header section and an expanding Word table for detail rows.


This demo uses the setDataSource and setRepeatBlock methods together.  The SetDataSource method is used to assign all of the single-value items to the order header and total 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

   public void GenerateDocument()
        {
            // Create an instance of WordTemplate
            WordTemplate wt = new WordTemplate();
 
            // Open the template document
            string templatePath = @"..\..\WordTemplateFiles\PurchaseOrderTemplate.docx";
            wt.Open(templatePath);
 
            // Query the database for header and detail information.
            // Set these DataTables as WordTemplate data sources.
           
            DataTable dtHeader = GetOrderHeaderData(@"..\..\WordData\PurchaseOrderDemoHeaderData.csv");
            DataTable dtDetail = GetOrderDetailData(@"..\..\WordData\PurchaseOrderDemoDetailData.csv");
            wt.SetDataSource(dtHeader);
            wt.SetRepeatBlock(dtDetail, "OrderDetailQuery");
            wt.Process();
 
            // Save the document to the disc
            wt.Save(@"..\..\WordOutputFiles\PurchaseOrder_output.docx");
        }