Powered by SpreadsheetGear
<%@ Page Language="VB" %>
<!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>.NET Spreadsheet Component Calculation Sample Using VB.NET and Microsoft Excel Compatible Spreadsheet Component for Microsoft .NET, ASP.NET, C#, VB.NET, XLS and Microsoft Visual Studio .NET</title>
<meta content=".NET spreadsheet component calculation sample using Visual Basic .NET 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="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
        ' Open the workbook.
        Dim filename As String = Server.MapPath("files/simpleloancalc.xls")
        Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook(filename)
        ' Get IRange for cells from defined names.
        Dim pv As SpreadsheetGear.IRange = workbook.Names("pv").RefersToRange
        Dim rate As SpreadsheetGear.IRange = workbook.Names("rate").RefersToRange
        Dim nper As SpreadsheetGear.IRange = workbook.Names("nper").RefersToRange
        ' Is the form being submitted?
        If Page.IsPostBack Then
            ' Copy the web form values to the worksheet.
            pv.Formula = TextBoxAmount.Text
            rate.Formula = TextBoxRate.Text
            nper.Formula = TextBoxPeriods.Text
        End If
        ' 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
    End Sub 'Page_Load
<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>.NET Spreadsheet Component Calculation Sample<br />Using Visual Basic .NET 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>