Table of Contents


Setting Up the Templates

In the downloadable TODO ADD FILE REFERENCE, there is a completed template file located in ComleteFinancialReport/templates/Part2_Financial_Template.xlsx.
A copy of the completed template file is also available TODO ADD FILE REFERENCE.

Getting Started

In this tutorial ExcelApplication is being used to join two Worksheets into one Workbook. These two worksheets were created in Part 1 and Part 2 of this tutorial.

This example assumes an understanding of ExcelTemplate. If you are not familiar with how to set up an Excel template with data markers, please go through the Simple Expense Summary first.

Adding an ExcelWriter Reference in Visual Studio

In the sample code, the reference to SoftArtisans.OfficeWriter.ExcelWriter.dll has already been added to the CompleteFinancialReport project.

Create a .NET project and add a reference to the ExcelWriter library.

  1. Open Visual Studio and create a .NET project.
  2. Add a reference to SoftArtisans.OfficeWriter.ExcelWriter.dll

Writing the Code

1. Include the SoftArtisans.OfficeWriter.ExcelWriter namespace in the code behind

using SoftArtisans.OfficeWriter.ExcelWriter;

2. In the method that will run the report, instantiate the ExcelTemplate object.

ExcelTemplate XLT = new ExcelTemplate();

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

XLT.Open(Page.MapPath("//templates//Part2_Financial_Template.xlsx"));

4. Create a DataBindingProperties object. None of the binding properties will be changed for this tutorial, but DataBindingProperties is a required parameter in ExcelTemplate data binding methods.

DataBindingProperties dataProps = XLT.CreateDataBindingProperties();

Data Binding

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

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 data directory. There is a copy of the CSV parser, GenericParsing.dll in the bin directory of the project GetCSVData is defined in Part2.aspx.cs in a region marked Utility Methods.

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:

DataTable dtAssets = GetCSVData("//data//Assets.csv");
DataTable dtLosses = GetCSVData("//data//Losses.csv");
DataTable dtOther = GetCSVData("//data//Other.csv");

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

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

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

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

XLT.Process();

4. Call ExcelTemplate.Save() to save the final file.

XLT.Save(Page.Response, "temp.xlsx", false);

Final Code

using SoftArtisans.OfficeWriter.ExcelWriter;
...

TBA

Downloads

TBA