...
2. In the method that will actually run the report, instantiate the ExcelTemplate
object.
Code Block |
---|
ExcelTemplate XLT = new ExcelTemplate(); |
3. Open the template file with the ExcelTemplate.Open
method.
Code Block |
---|
XLT.Open(Page.MapPath("//templates//part1_template.xlsx")); |
4. Create a DataBindingProperties
object. Although we won't be changing any of the binding properties, a DataBindingProperties
is a required parameter in all ExcelTemplate
data binding methods.
...
7. Get the data for the Top 5 Expenses and All Expenses data sets.
In this casethe sample code, we chose to parse CSV files that contain query results from the AdventureWorks2008 database to make running the sample code easier. These calls are to a helper method GetCSVData
that parses the CSV files and returns a DataTable
with the values.
...
Code Block |
---|
XLT.BindData(dtTop5, "Top 5 Expenses", dataProps); XLT.BindData(dtAll, "All Expenses", dataProps); |
9. Call ExcelTemplate.Process()
to import the data into the file.
Code Block |
---|
XLT.Process(); |
10. Call ExcelTemplate.Save
to save the output file.
ExcelTemplate
has several output options: save to disk, save to a stream, stream the output file in a page's Response
inline or as an attachment.
...
3. Add some borders to the cells in the Top Expenses and All Expenses tables. Then format the column headers as desired. Below is a screen shot of the final template:
4. Run the code with the updated template file. Here's a screenshot of the output with all the formatting applied:
...