...
Excerpt |
---|
Very simple sample that demonstrates how to use strings of data for an Excel report. |
Technical overview information.
The BindCellData method is used to assign single values to data markers with ExcelTemplate.
To mark where single values on a template would go, place a single object data marker, formatted:%%=$variablename.
Note | ||||
---|---|---|---|---|
| ||||
|
Code
Code Block |
---|
Insertpublic codeclass here |
Downloads
...
StringDataSource
{
private string recipientName;
private string recipientCompany;
/// <summary>
/// Build the report with ExcelTemplate
/// </summary>
public void GenerateReport()
{
this.recipientName = "Jon Smith";
this.recipientCompany = "SoftArtisans";
// Create an instance of SoftArtisans ExcelTemplate
ExcelTemplate xlt = new ExcelTemplate();
// Open the template workbook
string templatePath = @"..\..\templates\StringDataSourceTemplate.xlsx";
xlt.Open(templatePath);
// Bind the variables to the template datamarkers
// %%=$RecipientName
xlt.BindCellData(recipientName, "RecipientName", xlt.CreateDataBindingProperties());
// %%=$RecipientCompany
xlt.BindCellData(recipientCompany, "RecipientCompany", xlt.CreateDataBindingProperties());
// Process the template to populate it with the Data Source data
xlt.Process();
// Save the report by streaming to the client
xlt.Save(@"..\..\Output\StringDataSource_output.xlsx");
}
}
|
Downloads
Template: StringDataSourceTemplate.xlsx
Output: StringDataSource_output.xlsx