Page tree

Versions Compared

Key

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

...

3. Open the template file with the ExcelTemplate.Open method.

Code Block
 XLT.Open(Page.MapPath("//templates//Part1_Financial_Template.xlsx"));

...

Code Block
DataBindingProperties dataProps = XLT.CreateDataBindingProperties();

Data Binding

1.Get the data for the Assets, Losses, and Other datasets

...

These calls are to a helper method GetCSVData that parses the CSV files and returns a DataTable with the values.

If you are following in your own project and would like to parse the CSV files as well, you will need to:

  • Add a reference to GenericParsing.dll
  • Include GeneringParsing at the top of your code.
  • Add the GetCSVData method that can be found in the sample code.
Code Block
DataTable dtAssets = GetCSVData("//data//Assets.csv");
DataTable dtLosses = GetCSVData("//data//Losses.csv");

DataTable dtOther = GetCSVData("//data//Other.csv");

2. Create the datasets for the header row. Recall the optional modifier for the "Division" tag. This tutorial will not bind any data for that tag to demonstrate the function.

Code Block
//Create the array of header values. This example only binds a single item
string[] headerValues = { "2011" };



//Create the array of header names.

string[] headerNames = { "FiscalYear" };

3. Use ExcelTemplate.BindData to bind the data for the Top and Details Sales data sets.

Code Block
XLT.BindData(dtAssets, "Assets", bindingProps);
XLT.BindData(dtLosses, "Losses", bindingProps);

XLT.BindData(dtOther, "Other", bindingProps);

4. Use the ExcelTemplate.BindRowData method to bind the header data to the data markers in the template file (i.e. %%=Header.FiscalYear).

Code Block

XLT.BindRowData(headerValues, headerNames, "Header", bindingProps);

5. Call ExcelTemplate.Process() to import all data into the file.

Code Block

 XLT.Process();

We are not saving the file, since we will be using ExcelApplication to access the file and post-process.

Without the post processing, the populated file will persist the column width and heights. It should look something like this: Image Added

Post-Processing

Final Code

...