...
Code Block |
---|
//Variables needed for calculations: private double principal = 1000.00d; private double apr = 2.99d; private int numyears = 5; private DateTime date = DateTime.Now; /// <summary> /// Build the report with ExcelTemplate /// </summary> public void GenerateReport() { // Create an instance of ExcelTemplate ExcelTemplate xlt = new ExcelTemplate(); // Open the template workbook string templatePath = @"..\..\templates\LoanCalculatorTemplate.xlsx"; xlt.Open(templatePath); // Pass the data to the BindCellData method // and specify the data source name DataBindingProperties bindingProperties = xlt.CreateDataBindingProperties(); xlt.BindCellData(principal, "Principal", bindingProperties); xlt.BindCellData(apr / 100, "APR", bindingProperties); xlt.BindCellData(numyears, "N", bindingProperties); xlt.BindCellData(date, "Date", bindingProperties); // Call the Process() method to populate the template with the data source values xlt.Process(); // Save the report xlt.Save(@"..\..\Output\LoanCalculator_output.xlsx"); } } |
Downloads
Template and populated output: LoanCalculatorTemplate.xlsx
Output: LoanCalculator_output.xlsx