Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

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.

http://windemo.softartisans.com/OfficeWriter/latest/WordWriter/Web/CSharp/ShowCode.aspx?p=wordtemplate/PurchaseOrder.aspx.cs

Code

Code

Code Block

   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");
        }