# spreadsheet-editor-formula

> Spreadsheet editor populated from a prebuilt formula.xlsx byte payload loaded at startup.

**Framework:** aspnet-mvc  **Component:** Spreadsheet  **Variant:** formula

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/spreadsheet-editor-formula.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.Spreadsheet
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/spreadsheet-editor-formula/SpreadsheetEditor.cshtml

```cshtml
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Spreadsheet

@section ControlsSection{
    <div class="control-section">
        @Html.EJS().Spreadsheet("spreadsheet").ShowRibbon(false).Created("createdHandler").Sheets(sheet =>
   {
       sheet.Name("Stock Details").SelectedRange("F15").Ranges(ranges =>
       {
           ranges.DataSource((IEnumerable<object>)ViewData["formulaData"]).Add();
       }).Rows(row =>{
           row.Height(40).Cells(cell => {
               cell.Index(3).Value("High (+)").Add();
               cell.Value("Low (-)").Add();
           }).Add();
           row.Height(25).Index(11).Cells(cell => {
               cell.Index(3).Value("Average profit:").Add();
               cell.Index(5).Formula("=AVERAGE(Profit)").Format("0.00").Add();
           }).Add();
           row.Height(25).Cells(cell => {
               cell.Index(3).Value("Maximum stock value:").Add();
               cell.Index(5).Formula("=MAX(High)").Format("0.00").Add();
           }).Add();
           row.Height(25).Cells(cell => {
               cell.Index(3).Value("Minimum stock value:").Add();
               cell.Index(5).Formula("=MIN(E2:E11)").Add();
           }).Add();
           row.Height(25).Cells(cell => {
               cell.Index(3).Value("Non-profitable days:").Add();
               cell.Index(5).Formula("=COUNTIF(F2:F11,\"<=0\")").Add();
           }).Add();
       }).Columns(column => {
           column.Width(100).Add();
           column.Width(130).Add();
           column.Width(140).Add();
           column.Width(140).Add();
           column.Width(130).Add();
           column.Width(130).Add();
       }).Add();
   }).DefinedNames(definedName => {
       definedName.Name("Profit").RefersTo("=F2:F11").Add();
       definedName.Name("High").RefersTo("=D2:D11").Add();
   }).Render()
    </div>
}

<script>
    function createdHandler() {
        // Applies cell and number formatting to specified range of the active sheet
        this.cellFormat({ fontWeight: 'bold', backgroundColor: '#279377', color: '#fff', textAlign: 'center', fontSize: '14px' }, 'A1:F1');
        this.cellFormat({ backgroundColor: '#F2F2F2' }, 'A2:F11');
        this.cellFormat({ fontWeight: 'bold', backgroundColor: '#EEEEEE' }, 'A12:F15');
        this.numberFormat('0.00', 'F2:F11');
        this.numberFormat('m/d/yyyy', 'A2:A11');
    }
</script>

<style>
    .control-section {
        height: 550px;
    }
    #sb-content .e-spreadsheet .e-tab .e-tab-text {
        display: inherit;
    }
</style>

```

### src/components/spreadsheet-editor-formula/SpreadsheetEditorController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EJ2MVCSampleBrowser.Controllers.Spreadsheet
{
    public partial class SpreadsheetController : Controller
    {
        public ActionResult Formula()
        {
           List<object> formulaData = new List<object>()
            {
                new { Date= "08-01-2019", Open= "2625.75", Close= "2640.75", High= "2634.45", Low= "2620.65", Profit= "=C2-B2" },
                new { Date= "08-02-2019", Open= "2640.75", Close= "2638.75", High= "2640.75", Low= "2638.75", Profit= "=C3-B3" },
                new { Date= "08-03-2019", Open= "2638.75", Close= "2697.65", High= "2690.25", Low= "2647.65", Profit= "=C4-B4" },
            };
            ViewData["formulaData"] = formulaData;
           return View("~/Views/Home/spreadsheet-editor/formula/SpreadsheetEditor.cshtml");
        }
    }
}
```
