Setting up the Template
Intro
Note |
---|
This is Part 2 of a 2-part tutorial series for the Sales Invoice scenario. It is recommended that you complete Part 1 - Getting Started before starting this section. |
Info |
---|
title | Following the Sample |
---|
|
There is a downloadable ADD FILE REF with completed templates and code. The completed example of the template is available under templates/Part2_Invoice_Template.xlsx. The code for this part of the tutorial can be found in Part2.aspx.cs. |
This part focuses on adding repeating data to an order summary. There are slight modifications to the template and code from Part 1.
Adding Repeat Blocks
Adding a WordWriter Reference in Visual Studio
Writing the Code
Final Code
Downloads
Next Steps
Note |
---|
For information on writing this code, see Part 1 - Getting Started . |
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 details 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 details data source to import a single row of data
WT.SetDataSource(detailsArray, detailColNames, "OrderDetails");
//Process to import the data to the template
WT.Process();
WT.Save(Response, "Part2_Output.docx", false);
|
Downloads
You can download the code for the Basic WordWriter Tutorials as a Visual Studio solution, which includes the Simple Expense Summary.