# spreadsheet-editor-formula

> Spreadsheet sample demonstrating formulas, references, and calculation behaviors.

**Framework:** javascript  **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/javascript/spreadsheet-editor-formula.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-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/spreadsheet-editor.html

```html
<div class="control-section">
    <div id="container"></div>
</div>

<style>
    .control-section .control-wrapper {
        height: calc(100vh - 230px);
    }

    #sb-content .e-spreadsheet .e-tab .e-tab-text {
        display: inherit;
    }

    .ej2-new .control-section {
        height: 550px;
    }
    .e-spreadsheet .e-main-panel .e-main-content{
        margin-left: 0 !important;
    }
</style>
<!-- custom code end -->
```

### src/components/spreadsheet-editor-formula/spreadsheet-editor.ts

```typescript
import { Spreadsheet, type SheetModel, type CellStyleModel } from '@syncfusion/ej2-spreadsheet';
import { formulaData } from '../datasource/spreadsheet-editor-data';

export function initSpreadsheetEditorFormula(): void {
    let style: CellStyleModel = { fontWeight: 'bold', backgroundColor: '#279377', color: '#fff', textAlign: 'center',
        verticalAlign: 'middle', fontSize: '14px' };
    let sheets: SheetModel[] = [{
        name: 'Stock Details',
        rows: [{
            height: 40
        },
        {
            index: 11,
            cells: [
                { index: 3, value: 'Average profit:' },
                { index: 5, formula: '=AVERAGE(Profit)', format: '0.00' },
            ],
            height: 25
        },
        {
            index: 12,
            cells: [
                { index: 3, value: 'Maximum stock value:' },
                { index: 5, formula: '=MAX(High)', format: '0.00' }
            ],
            height: 25
        },
        {
            index: 13,
            cells: [
                { index: 3, value: 'Minimum stock value:' },
                { index: 5, formula: '=MIN(E2:E11)' },
            ],
            height: 25
        }, {
            index: 14,
            cells: [
                { index: 3, value: 'Nonprofitable days:' },
                { index: 5, formula: '=COUNTIF(F2:F11,"<=0")' },
            ],
            height: 25
        }],
        columns: [{ width: 100 }, { width: 130 }, { width: 140 }, { width: 140 }, { width: 130 }, { width: 130 }],
        selectedRange: 'F15',
        ranges: [{ dataSource: formulaData }]
    }];

    //Initialize Spreadsheet component
    let spreadsheet: Spreadsheet = new Spreadsheet({
        sheets: sheets,
        showRibbon: false,
        //Initializing defined names and its range
        definedNames: [{
            name: 'Profit', refersTo: '=F2:F11'
        },
        {
            name: 'High', refersTo: '=D2:D11'
        }],
        created: (): void => {
            spreadsheet.cellFormat(style, 'A1:F1');
            spreadsheet.cellFormat({ fontWeight: 'bold', backgroundColor: '#EEEEEE' }, 'A12:F15');
            spreadsheet.numberFormat('0.00', 'F2:F11');
            spreadsheet.numberFormat('m/d/yyyy', 'A2:A11');
        }
    });
    spreadsheet.appendTo('#container');
}

```
