Table of Contents | ||||
---|---|---|---|---|
|
Setting Up the Template
Getting Started
In this tutorial ExcelTemplate is being used to populate data and ExcelApplication is being used to format the data. This part of the tutorial will make use of data marker modifiers.
Note |
---|
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. |
Using Modifiers
The template should resemble this upon completion:
This template uses two different data marker modifiers - fieldname and optional.
The fieldname modifier shows the fieldname of the column being bound. It will not bind any additional data. It is used like this:
The optional modifier allows that data marker to be ignored on data binding. If you have a column that may be empty, the optional modifier allows you to bind the data set regardless. It is used like this:
Conditional Formatting
ExcelTemplate will persist conditional formatting in a template. In this tutorial, conditional formatting is applied to the "Other" table. It sets negative numbers to be red and bold.
Adding an ExcelWriter Reference in Visual Studio
Info | ||
---|---|---|
| ||
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.
- Open Visual Studio and create a .NET project.
- The sample code uses a web application.
- Add a reference to SoftArtisans.OfficeWriter.ExcelWriter.dll
- SoftArtisans.OfficeWriter.ExcelWriter.dll is located under Program Files > SoftArtisans > OfficeWriter > dotnet > bin
Writing the Code
1. Include the SoftArtisans.OfficeWriter.ExcelWriter namespace in the code behind
Code Block |
---|
using SoftArtisans.OfficeWriter.ExcelWriter; |
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_Financial_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.
Code Block |
---|
DataBindingProperties dataProps = XLT.CreateDataBindingProperties(); |