# spreadsheet-editor-data-validation

> Spreadsheet editor with data validation feature using gross pay calculation as an example.

**Framework:** react  **Component:** SpreadsheetEditor  **Variant:** data-validation

## 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/react/ts/spreadsheet-editor-data-validation.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-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-data-validation/SpreadSheetEditor.tsx

```tsx
import React from 'react';
import { SpreadsheetComponent, SheetDirective, RowsDirective, CellsDirective, CellDirective, RowDirective, SheetsDirective, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective } from '@syncfusion/ej2-react-spreadsheet';
import { grossPay } from '../datasource/spreadsheet-editor.data';
import '../spreadsheet-editor.css';

/**
 * Data Validation sample
 */

function DataValidation(): React.ReactElement {
    let spreadsheet: SpreadsheetComponent;
    const currencyFormat: string = '$#,##0.00';
    function onCreated(): void {
        spreadsheet.merge('A1:I2');
        spreadsheet.setBorder({ border: '1px solid #A6A6A6' }, 'A1:I13');
        spreadsheet.cellFormat({ textAlign: 'center', verticalAlign: 'middle' }, 'A3:I13');
        spreadsheet.cellFormat({ backgroundColor: '#B3FFB3', fontWeight: 'bold' }, 'A3:I3');
        spreadsheet.numberFormat(currencyFormat, 'H4:I13');
        spreadsheet.numberFormat('m/d/yyyy', 'C4:C13');
        spreadsheet.wrap('H3:I3');
        //Add Data validation to range.
        spreadsheet.addDataValidation({ type: 'WholeNumber', operator: 'LessThan', value1: '9', ignoreBlank: false }, 'G4:G13');
        spreadsheet.addDataValidation({ type: 'TextLength', operator: 'GreaterThan', value1: '3', ignoreBlank: false }, 'B4:B13');
        spreadsheet.addDataValidation({ type: 'Time', operator: 'GreaterThan', value1: '8:00:00 AM', ignoreBlank: false }, 'E4:E13');
        spreadsheet.addDataValidation({ type: 'Time', operator: 'LessThan', value1: '6:00:00 PM', ignoreBlank: false }, 'F4:F13');
        spreadsheet.addDataValidation({ type: 'List', value1: 'Mon, Tue, Wed, Thu, Fri', ignoreBlank: false }, 'D4:D13');
        spreadsheet.addDataValidation({ type: 'WholeNumber', operator: 'LessThan', value1: '=H5', ignoreBlank: false }, 'I4:I13');
        //Highlight Invalid Data.
        spreadsheet.addInvalidHighlight('G4:G13');
        spreadsheet.addInvalidHighlight('I4:I13');
    }
    return (
        <div className='control-pane'>
            <div className='control-section spreadsheet-control'>
                <SpreadsheetComponent ref={(ssObj: SpreadsheetComponent | null) => { if (ssObj) spreadsheet = ssObj }} created={onCreated}>
                    <SheetsDirective>
                        <SheetDirective name='Gross Pay' selectedRange='D13'>
                            <RangesDirective>
                                <RangeDirective dataSource={grossPay} startCell='A3' ></RangeDirective>
                            </RangesDirective>
                            <RowsDirective>
                                <RowDirective>
                                    <CellsDirective>
                                        <CellDirective value='TimeSheet Calculation' style={{ fontSize: '20pt', fontWeight: 'bold', textAlign: 'center', backgroundColor: '#B3FFB3', verticalAlign: 'middle' }} ></CellDirective>
                                    </CellsDirective>
                                </RowDirective>
                                <RowDirective index={13}>
                                    <CellsDirective>
                                        <CellDirective index={7} value='Total Gross' style={{ border: '1px solid #A6A6A6', textAlign: 'center', verticalAlign: 'middle', fontWeight: 'bold' }}></CellDirective>
                                        <CellDirective index={8} formula='=Sum(I4:I13)' format={currencyFormat} style={{ border: '1px solid #A6A6A6', textAlign: 'center', verticalAlign: 'middle', fontWeight: 'bold' }}></CellDirective>
                                    </CellsDirective>
                                </RowDirective>
                            </RowsDirective>
                            <ColumnsDirective>
                                <ColumnDirective width={88}></ColumnDirective>
                                <ColumnDirective width={120}></ColumnDirective>
                                <ColumnDirective width={106}></ColumnDirective>
                                <ColumnDirective width={98}></ColumnDirective>
                                <ColumnDirective width={110}></ColumnDirective>
                                <ColumnDirective width={110}></ColumnDirective>
                                <ColumnDirective width={110}></ColumnDirective>
                                <ColumnDirective width={98}></ColumnDirective>
                                <ColumnDirective width={130}></ColumnDirective>
                            </ColumnsDirective>
                        </SheetDirective>
                    </SheetsDirective>
                </SpreadsheetComponent>
            </div>
        </div>
    )
}
export default DataValidation;
```
