# spreadsheet-editor-protection

> Spreadsheet sample protecting workbooks with sheet-level and cell-level security.

**Framework:** javascript  **Component:** Spreadsheet  **Variant:** protection

## 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-protection.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-protection/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-protection/spreadsheet-editor.ts

```typescript
import { Spreadsheet, type CellRenderEventArgs, getFormatFromType } from '@syncfusion/ej2-spreadsheet';
import { protectSheet } from '../datasource/spreadsheet-editor-data';
export function initSpreadsheetEditorProtection(): void {

    let numberFormat: string = '$#,##0.00';
    //Initialize Spreadsheet component
    let spreadsheet: Spreadsheet = new Spreadsheet({
        // To protect the workbook
        password: 'spreadsheet',
        sheets: [{
            isProtected: true,
            name: 'EMI Calculator',
            rows: [{
                cells: [{
                    index: 1,
                    value: 'Home Loan Calculator',
                    style: {
                        textAlign: 'center',
                        fontWeight: 'bold'
                    }
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Loan Amount:'
                }, {
                    value: '100000',
                    format: numberFormat
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Interest Rate:'
                }, {
                    value: '0.08',
                    format: getFormatFromType('Percentage')
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Periods (terms in year):'
                }, {
                    value: '1'
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Start Date:'
                }, {
                    value: '03-03-2020'
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Loan EMI:'
                }, {
                    value: '8698.84',
                    format: numberFormat
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Number of Payments:'
                }, {
                    value: '12'
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Total Repayment Amount:'
                }, {
                    value: '104386.11',
                    format: numberFormat
                }]
            }, {
                cells: [{
                    index: 1,
                    value: 'Total Interest Amount:'
                }, {
                    value: '4386.11',
                    format: numberFormat
                }]
            }],
            columns: [{
                index: 1,
                width: 190
            }, {
                width: 100
            }]
        }, {
            isProtected: true,
            name: 'EMI Schedule',
            ranges: [{
                dataSource: protectSheet,
                showFieldAsHeader: true
            }],
            rows: [{
                index: 0,
                cells: [
                    {
                        style: {
                            textAlign: 'center',
                            fontWeight: 'bold'
                        }
                    }, {
                        style: {
                            textAlign: 'center',
                            fontWeight: 'bold'
                        }
                    }, {
                        style: {
                            textAlign: 'center',
                            fontWeight: 'bold'
                        }
                    }, {
                        style: {
                            textAlign: 'center',
                            fontWeight: 'bold'
                        }
                    }, {
                        style: {
                            textAlign: 'center',
                            fontWeight: 'bold'
                        }
                    }, {
                        style: {
                            textAlign: 'center',
                            fontWeight: 'bold'
                        }
                    }]
            }
            ],
            columns: [{
                index: 1,
                width: 110
            }, {
                width: 85
            }, {
                width: 85
            }, {
                width: 80
            }, {
                width: 90
            }]
        }],
        openUrl: 'https://document.syncfusion.com/web-services/spreadsheet-editor/api/spreadsheet/open',
        saveUrl: 'https://document.syncfusion.com/web-services/spreadsheet-editor/api/spreadsheet/save',
        created: () => {
            //Applied number formatting to a range
            spreadsheet.numberFormat(numberFormat, 'EMI Schedule!C2:F13');
            spreadsheet.numberFormat('m/d/yyyy', 'EMI Calculator!C5:C5');
            spreadsheet.numberFormat('m/d/yyyy', 'EMI Schedule!B2:B13');
        },
        beforeCellRender: (args: CellRenderEventArgs) => {
            //Merged cells using custom code
            if (spreadsheet.activeSheetIndex === 0 && args.address === 'B1') {
                (args.element as HTMLTableCellElement).colSpan = 2;
            }
        }
    });
    //Render initialized Spreadsheet component
    spreadsheet.appendTo('#container');
}

```
