...
Code Block |
---|
public class DataMarkerOptions
{
/// <summary>
/// Build the report with ExcelTemplate
/// </summary>
public void GenerateReport()
{
/* This 2D Object[][] array will hold the values to be imported */
object[,] values = {
/*employee ID*/ {1, 2, 3, 4},
/*Last Name*/ {"Davolio", "Fuller", "Leverling", "Peacock"},
/*First Name*/ {"Nancy", "Andrew", "Janet", "Margaret"},
/*Title*/ {"Sales Rep", "VP of Sales", "Sales Rep", "Sales Rep"},
/*Zip*/ {"02139","02144","23451","00213"}
};
// These are the field names
string[] colnames = { "EmployeeID", "LastName", "FirstName", "Title", "Zip" };
// Create an instance of ExcelTemplate
ExcelTemplate xlt = new ExcelTemplate();
// Open the template workbook
string templatePath = @"..\..\ExcelTemplateFiles\DataMarkerOptionsTemplate.xlsx";
xlt.Open(templatePath);
// Pass colnames and values arrays to BindData()
DataBindingProperties bindingProperties = xlt.CreateDataBindingProperties();
bindingProperties.MaxRows = ExcelTemplate.ALL_ROWS;
bindingProperties.Transpose = true;
xlt.BindData(values, colnames, "dSource", bindingProperties);
// Call the process() method to populate the template with the data source values
xlt.Process();
// Save the report
xlt.Save(@"..\..\ExcelOutputFiles\DataMarkerOptions_output.xlsx");
}
}
|
...