Powered by SpreadsheetGear
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!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>C# Spreadsheet Component Evaluate Formula Using ASP.NET and SpreadsheetGear</title>
<meta content="C# spreadsheet component evaluate formula sample demonstrating 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)
        if (Page.IsPostBack)
            // Create a new empty workbook and get the first sheet. 
            SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
            SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets[0]; 
            // Evaluate the input formula
            object result = worksheet.EvaluateValue(TextBox1.Text); 
            // Display the result to the user
            String displayValue;
            if (result == null)
                displayValue = "Empty cell or invalid formula.";
            else if (result is SpreadsheetGear.ValueError)
                SpreadsheetGear.ValueError valueError = (SpreadsheetGear.ValueError)result;
                displayValue = "Value Error: #" + valueError.ToString().ToUpper() + "!";
                displayValue = result.ToString();   
            LabelResult.Text = "<strong>Result calculated from EvaluateValue</strong>: " + displayValue;
            TextBox1.Text = "TEXT(STDEV(1, 2, 3, 4), \"0.00\")";
<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>C# Spreadsheet Component Evaluate Formula Sample<br />for ASP.NET Using <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="3">Evaluate Formula Sample</td>
      <td>Enter Excel compatible formula to evaluate:</td>
      <td><asp:TextBox id="TextBox1" Columns="80" runat="server"/></td>
      <td align="right"><asp:Button ID="ButtonSubmit" Text="Evaluate" runat="server"/></td>
  <br />
  <asp:Label id="LabelResult" Font-Size="14px" runat="server"/>
<h6>Copyright 2005 © SpreadsheetGear LLC. All Rights Reserved.<br /><a href="https://www.spreadsheetgear.com">www.spreadsheetgear.com</a></h6>