Table of Contents | ||||
---|---|---|---|---|
|
Introduction
...
...
This tutorial assumes that the coder knows how to set up an Excel Template using data markers and Excel cell formatting. The .XLSX template file is available here.
ExcelTemplate vs. ExcelApplication
...
The
...
ExcelTemplate
object is used for template-driven document generation. This object opens an ExcelWriter template file, populates it with data from a specified data source, and generates a new Excel workbook. An Excel file uploaded as an ExcelTemplate object
is not directly modifiable at runtime.
...
The ExcelApplication
...
object is an Excel file engine that can be used to create, open, modify, and save workbooks. A single instance of ExcelApplication
can generate multiple Excel workbooks.
This tutorial opens an Excel template file formatted as an for ExcelTemplate
origin file (i.e. it contains formatted data markers) and makes customizations using ExcelApplication
object. This means that the file can be copied based upon the , based on a user's specification using the ExcelApplication CopySheet method. This method copies a worksheet (including its formatted data markers) to another location in the workbook. The method has three parameters:
...
selections. In particular, it highlights the functionality of the CopySheet
method. Then data is bound to the template using ExcelTemplate
, again, based on a user's selections.
Note |
---|
This tutorial assumes a basic understanding of the |
Setting up the template
Info | ||
---|---|---|
| ||
In the downloadable C# project, there is a completed template file located in ExtendedSalesSummary/templates/template.xlsx. |
The template file should look something like this:
One advanced data marker format has been used in the above template. The data marker entitled Sales Summary - In the template, the %%=Header.FiscalYear
data marker is referenced in a formula. In the header, there is a formula =CONCATENATE("Sales Summary - ", N1)
, where N1 is the cell that actually contains the %%=Header.FiscalYear
references another cell for the content. The below image is the data marker that was input and is how ExcelWriter will identify the appropriate fields to bind data.
Cell N1 was hidden by using a custom format where the field was filled with ';;;'.
Info |
---|
In the sample code, the complete template file is located in ExtendedSalesSummary/templates/template.xlsx .The template is also available here. |
data marker. This is shown in the image below.
START HERE
Adding an ExcelWriter Reference in Visual Studio
...