# spreadsheet-editor-data-validation

> Spreadsheet sample demonstrating data validation feature with gross pay calculation as an example.

**Framework:** angular  **Component:** Spreadsheet  **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/angular/spreadsheet-editor-data-validation.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-angular-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/spreadsheet-editor.component.html

```html
<div class="control-section">
    <ejs-spreadsheet #spreadsheet (created)="created()">
        <e-sheets>
            <e-sheet name="Gross Pay">
                <e-ranges>
                    <e-range [dataSource]="grossPay" startCell="A3"></e-range>
                </e-ranges>
                <e-rows>
                    <e-row>
                        <e-cells>
                            <e-cell value="Gross Pay Calculation" [style]="{fontSize: '20pt', fontWeight: 'bold', textAlign: 'center', backgroundColor: '#B3FFB3', verticalAlign: 'middle'}"></e-cell>
                        </e-cells>
                    </e-row>
                    <e-row index= "13">
                        <e-cells>
                            <e-cell index= "7" value="Total Gross" [style]="{border: '1px solid #A6A6A6', textAlign: 'center', verticalAlign: 'middle', fontWeight: 'bold'}"></e-cell>
                            <e-cell index= "8" formula="=Sum(I4:I13)" [format]="currencyFormat" [style]="{border: '1px solid #A6A6A6', textAlign: 'center', verticalAlign: 'middle', fontWeight: 'bold'}"></e-cell>
                        </e-cells>
                    </e-row>
                </e-rows>
                <e-columns>
                    <e-column [width]=88></e-column>
                    <e-column [width]=120></e-column>
                    <e-column [width]=106></e-column>
                    <e-column [width]=98></e-column>
                    <e-column [width]=110></e-column>
                    <e-column [width]=110></e-column>
                    <e-column [width]=110></e-column>
                    <e-column [width]=98></e-column>
                    <e-column [width]=130></e-column>
                </e-columns>
            </e-sheet>
        </e-sheets>
    </ejs-spreadsheet>
</div>
```

### src/components/spreadsheet-editor-data-validation/spreadsheet-editor.component.ts

```typescript
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { grossPay } from '../datasource/spreadsheet-editor-data';
import { SpreadsheetComponent, SpreadsheetModule } from '@syncfusion/ej2-angular-spreadsheet';
/**
 * Data Validation Spreadsheet Component
 */
@Component({
    selector: 'control-content',
    templateUrl: 'spreadsheet-editor.component.html',
    encapsulation: ViewEncapsulation.None,
    standalone: true,
    imports: [SpreadsheetModule]
})

export class DataValidationController {
    @ViewChild('spreadsheet')
    spreadsheetObj!: SpreadsheetComponent;
    data: Object[] = grossPay();
    currencyFormat: string = '$#,##0.00';
    public grossPay: Object[] = grossPay();
    created() {
        this.spreadsheetObj.merge('A1:I2');
        this.spreadsheetObj.setBorder({ border: '1px solid #A6A6A6' }, "A1:I13");
        this.spreadsheetObj.cellFormat({ textAlign: 'center', verticalAlign: 'middle'}, 'A3:I13');
        this.spreadsheetObj.cellFormat({ backgroundColor: '#B3FFB3', fontWeight : "bold"}, 'A3:I3');
        this.spreadsheetObj.numberFormat('$#,##0.00', 'H4:I13');
        this.spreadsheetObj.numberFormat('m/d/yyyy', 'C4:C13');
        this.spreadsheetObj.wrap('H3:I3');
        //Add Data validation to range.
        this.spreadsheetObj.addDataValidation({ type: 'WholeNumber', operator: 'LessThan', value1: '9', ignoreBlank: false }, 'G4:G13');
        this.spreadsheetObj.addDataValidation({ type: 'TextLength', operator: 'GreaterThan', value1: '3', ignoreBlank: false }, 'B4:B13');
        this.spreadsheetObj.addDataValidation({ type: 'Time', operator: 'GreaterThan', value1: '8:00:00 AM', ignoreBlank: false  }, 'E4:E13');
        this.spreadsheetObj.addDataValidation({ type: 'Time', operator: 'LessThan', value1: '6:00:00 PM', ignoreBlank: false  }, 'F4:F13');
        this.spreadsheetObj.addDataValidation({ type: 'List', value1: 'Mon, Tue, Wed, Thu, Fri', ignoreBlank: false  }, 'D4:D13');
        this.spreadsheetObj.addDataValidation({ type: 'WholeNumber', operator: 'LessThan', value1: '=H5', ignoreBlank: false }, 'I4:I13');
        //Highlight Invalid Data.
        this.spreadsheetObj.addInvalidHighlight('G4:G13');
        this.spreadsheetObj.addInvalidHighlight('I4:I13');
    }
}
```
