# Angular Spreadsheet Disabled Cells

The Spreadsheet allows you to protect specific cells from being edited by disabling them. When you export a Spreadsheet with disabled cells to Excel, the disabled cells become [locked protected cells](https://support.microsoft.com/en-gb/office/lock-cells-to-protect-them-in-excel-cb7835f6-9c37-4161-bb53-d1c410acaf21). Disabled cells are useful for locking auto-generated values, computed formulas, or protected reference data while keeping the rest of the Spreadsheet fully editable.

The following example demonstrates disabled cells in a Q1 Sales Performance Report. The **Rep ID** column and all formula-based cells are disabled by default. The Spreadsheet will display an error dialog when pasting into a disabled cell or dragging the fill handle over a disabled range.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/disabled-cells/source.txt)

## Configuring Cell Protection

To disable a cell, set the [`enable`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/cell#enable) property of the [`Cell`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/cell) object to `false`. A disabled cell retains its value and formatting, but the user cannot edit it.

```typescript
public sheets: SheetDescriptor[] = [{
    name: 'Invoice',
    rows: [{
        cells: [
            { value: 216321, textAlign: 'center', enable: false },
            { value: 'Calzone' }
        ]
    }]
}];
```

You can also toggle protection at runtime by accessing the underlying [`SpreadsheetWidget`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetwidget) instance of the [`SpreadsheetComponent`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcomponent) and calling the `enable()` method of the [`Range`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/range) to read and invert the current state.

```typescript
@ViewChild('spreadsheet') private spreadsheetRef: SpreadsheetComponent;

public toggleDisabled(disabled: boolean): void {
    const sheet = this.spreadsheetRef.spreadsheetWidget.activeSheet() as any;
    const ranges = ['A2:A11', 'E2:E11', 'F2:F11'];

    ranges.forEach(rangeRef => {
        const range = sheet.range(rangeRef);
        let enabled = range.enable();

        // Treat a null result as enabled before inverting the state.
        if (enabled === null) {
            enabled = true;
        }

        range.enable(!enabled);
    });
}
```

## Customizing Error Messages for Disabled Cells

The Spreadsheet displays a built-in error dialog when a user attempts to edit a disabled cell. For example, pasting content into a disabled cell or dragging the fill handle over a disabled range triggers the error dialog.

You can customize the default error messages using the [`<kendo-spreadsheet-messages>`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/custommessagescomponent) component. The following properties control the messages in the error dialog when a user attempts to modify a disabled cell:

* [`cannotModifyDisabled`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/custommessagescomponent#cannotmodifydisabled)—Sets the message text for the dialog that appears when the user tries to edit a single disabled cell.
* [`rangeDisabled`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/custommessagescomponent#rangedisabled)—Sets the message text for the dialog that appears when the edited range contains one or more disabled cells.

```html
<kendo-spreadsheet [sheets]="sheets">
    <kendo-spreadsheet-messages
        cannotModifyDisabled="This cell is protected and cannot be modified."
        rangeDisabled="The selected range contains one or more protected cells."
    ></kendo-spreadsheet-messages>
</kendo-spreadsheet>
```

## See Also

* [Data Binding](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/data-binding)
* [Data Validation](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/validations)
* [API Reference of the Cell](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/cell)
* [API Reference of the CustomMessagesComponent](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/custommessagescomponent)
