Powered by SpreadsheetGear
<%@ Page Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>ASP.NET Spreadsheet Component Calculation Sample Using C# and Microsoft Excel Compatible Spreadsheet Component for Microsoft .NET, ASP.NET, C#, VB.NET, XLS and Microsoft Visual Studio .NET</title>
<meta content="ASP.NET spreadsheet component calculation sample using C# and SpreadsheetGear, a royalty free Microsoft Excel compatible spreadsheet component for the Microsoft .NET Framework featuring the fastest and most complete calculation engine available. Create, read, modify, calculate and write Microsoft Excel workbooks from your Microsoft .NET, ASP.NET, C#, VB.NET and Microsoft Office solutions. Integrates with Microsoft Visual Studio .NET, including IntelliSense and Dynamic Help." name="description" />
<script language="C#" runat="server">
    void Page_Load(Object sender, EventArgs e)
        // Open the workbook.
        String filename = Server.MapPath("files/simpleloancalc.xls");
        SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(filename);
        // Get IRange for cells from defined names.
        SpreadsheetGear.IRange pv = workbook.Names["pv"].RefersToRange;
        SpreadsheetGear.IRange rate = workbook.Names["rate"].RefersToRange;
        SpreadsheetGear.IRange nper = workbook.Names["nper"].RefersToRange;
        // Is the form being submitted?
        if (Page.IsPostBack)
            // Copy the web form values to the worksheet.
            pv.Formula = TextBoxAmount.Text;
            rate.Formula = TextBoxRate.Text;
            nper.Formula = TextBoxPeriods.Text;
        // Copy the formatted worksheet values to the web form.
        TextBoxAmount.Text = pv.Text;
        TextBoxRate.Text = rate.Text;
        TextBoxPeriods.Text = nper.Text;
        // Display the result
        LabelPayment.Text = workbook.Names["payment"].RefersToRange.Text;
<style type="text/css">
    background-color: #EEEEEE;
    border-style: solid;
    border-width: 1px;
    border-color: #5959AA;
    color: #000000;
    font-size: 12px;
    background-color: #5959AA;
    color: #FFFFFF;
    font-weight: bold;
<body style="font-family: Verdana;">
<h5>ASP.NET Spreadsheet Component Calculation Sample<br />Using C# and <a href="https://www.spreadsheetgear.com/products/spreadsheetgear.net.aspx">SpreadsheetGear</a></h5>
<form id="form1" runat="server">
  <table class="tableStyle "cellpadding="4" cellspacing="0" >
    <tr class="tableHeaderStyle">
      <td colspan="2">Loan Calculator</td>
      <td align="right">Loan Amount (pv)</td>
      <td><asp:TextBox id="TextBoxAmount" Columns="12" runat="server"/></td>
      <td align="right">Interest Rate (rate)</td>
      <td><asp:TextBox id="TextBoxRate" Columns="8" runat="server"/></td>
      <td align="right">Total # of Periods (Nper)</td>
      <td><asp:TextBox id="TextBoxPeriods" Columns="8" runat="server"/></td>
      <td align="right">Payment</td>
      <td><asp:Label id="LabelPayment" runat="server"/></td>
      <td colspan="2" align="right"><asp:Button ID="ButtonSubmit" Text="Calculate" runat="server"/></td>
  <br />
  <table class="tableStyle "cellpadding="4" cellspacing="0" >
      <td colspan="2"><b>Notice These Features:</b>
          <li>Parses inputs, including currency, percent, date, time and fractions.</li>
          <li>Allows simple or complex formulas - Enter "=1% * 12" for Interest Rate (don't include the quotes).</li>
          <li>Returns nicely formatted results, including all Excel custom formatting options.</li>
          <li>Uses defined names to access cells (see the source code and workbook).</li>
<h6>Copyright 2005 © SpreadsheetGear LLC. All Rights Reserved.<br /><a href="https://www.spreadsheetgear.com">www.spreadsheetgear.com</a></h6>