Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example we have a sample loan calculator.  By simply binding the loan amount, annual interest rate, loan period and the start date of the loan, we can create a  report with a plan for how to pay off the loan in the given loan period. 

Note
iconfalse
titleRequirements

Excerpt

This sample requires OfficeWriter Enterprise Edition to be installed because the OfficeWriter Grouping and Nesting is only available in the Enterprise Edition of the product.

Note

\

Code\

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");
        }
    }

...