Page tree

Versions Compared

Key

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

...

Info
titleFollowing the Sample

In the sample project, we are parsing CSV files with query results, rather than querying a live database. The CSV files are available under the datadata _directory. There is a copy of the CSV parser, GenericParsing.dll in the _bin directory of the project GetCSVData is defined in Part1.aspx.cs in aregion marked Utility Methods.

...

The final output should resemble this:

Final Code

For information on writing this , see Part 1 - Getting Started .
Note
Code Block
Code Block
using SoftArtisans.OfficeWriter.WordWriter;
...
//Instantiate a new WordTemplate object
WordTemplate WT = new WordTemplate();

//Open the template file
WT.Open(Page.MapPath("//templates//Part2_Invoice_Template.docx"));

//Create the array of header values
object[] detailsArray 
    = { "Jane", "Doe", DateTime.Now.ToString("MM/dd/yy"), "13139.51", "558.43", "13697.94" };
//Create the array of column names
string[] detailColNames = { "FirstName", "LastName", "Date", "Subtotal", "Tax", "Total" };

//Get the order info datatable using GenericParser
DataTable dtOrderInfo = GetCSVData("//data//OrderInfo.csv");

//Set the repeat block to bind the data for multiple order items
WT.SetRepeatBlock(dtOrderInfo,"Repeat");
//Set the header data source to import a single row of data
WT.SetDataSource(orderHeader, orderHeaderColNames, "OrderHeader");

//Process to import the data to the template
WT.Process();

WT.Save(Response, "Part2_Output.docx", false);

...