Protect sheet in React Spreadsheet component

20 Jan 202324 minutes to read

Sheet protection helps you to prevent the users from modifying the data in the spreadsheet.

Protect Sheet

Protect sheet feature helps you to prevent the unknown users from accidentally changing, editing, moving, or deleting data in a spreadsheet. And you can also protect the sheet with password. You can use the isProtected property to enable or disable the Protecting functionality.

  • The default value for isProtected property is false.

By default in protected sheet, selecting, formatting, inserting, deleting functionalities are disabled. To enable some of the above said functionalities
the protectSettings options are used in a protected spreadsheet.

The available protectSettings options in spreadsheet are,

Options Uses
Select Cells Used to perform Cell Selection.
Format Cells Used to perform Cell formatting.
Format Rows Used to perform Row formatting.
Format Columns Used to perform Column formatting.
Insert Link Used to perform Hyperlink Insertions.
  • The default value for all protectSettings options are false.

By default, the Protect Sheet module is injected internally into the Spreadsheet to perform sheet protection function.

User Interface:

In the active Spreadsheet, the sheet protection can be done by any of the following ways:

  • Select the Protect Sheet item in the Ribbon toolbar under the Data Tab, and then select your desired options.
  • Right-click the sheet tab, select the Protect Sheet item in the context menu, and then select your desired options.
  • Use the protectSheet() method programmatically.

The following example shows Protect Sheet functionality in the Spreadsheet control.

import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective } from '@syncfusion/ej2-react-spreadsheet';
import { RangeDirective, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-spreadsheet';
import { budgetData, salaryData } from './datasource';

function App() {
    const spreadsheetRef = React.useRef(null);
    const dataBound = () => {
        let spreadsheet = spreadsheetRef.current;
        if (spreadsheet) {
            spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
            spreadsheet.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
            spreadsheet.protectSheet(1, { selectCells: false }, "syncfusion"); // protect sheet with password
        }
    };

    return (
        <div>
            <SpreadsheetComponent ref={spreadsheetRef} dataBound={dataBound} allowAutoFill={false} >
                <SheetsDirective>
                    <SheetDirective name={"Budget"} isProtected={true} protectSettings={{ selectCells: true }}>
                        <RangesDirective>
                            <RangeDirective dataSource={budgetData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                    <SheetDirective name={"Salary"}>
                        <RangesDirective>
                            <RangeDirective dataSource={salaryData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                </SheetsDirective>
            </SpreadsheetComponent>
        </div>
    );
};
export default App;

const root = createRoot(document.getElementById('root'));
root.render(<App />);
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective } from '@syncfusion/ej2-react-spreadsheet';
import { RangeDirective, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-spreadsheet';
import { budgetData, salaryData } from './datasource';

function App() {
    const spreadsheetRef = React.useRef<SpreadsheetComponent>(null);
    const dataBound = (): void => {
        let spreadsheet = spreadsheetRef.current;
        if (spreadsheet) {
            spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
            spreadsheet.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
            spreadsheet.protectSheet(1, { selectCells: false }, "syncfusion"); // protect sheet with password
        }
    };

    return (
        <div>
            <SpreadsheetComponent ref={spreadsheetRef} dataBound={dataBound} allowAutoFill={false} >
                <SheetsDirective>
                    <SheetDirective name={"Budget"} isProtected={true} protectSettings={{ selectCells: true }}>
                        <RangesDirective>
                            <RangeDirective dataSource={budgetData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                    <SheetDirective name={"Salary"}>
                        <RangesDirective>
                            <RangeDirective dataSource={salaryData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                </SheetsDirective>
            </SpreadsheetComponent>
        </div>
    );
};
export default App;

const root = createRoot(document.getElementById('root')!);
root.render(<App />);
export let budgetData = [
    {
        "Expense Type": "Housing",
        "Projected Cost": 7000,
        "Actual Cost": 7500,
        "Difference": -500,
    },
    {
        "Expense Type": "Transportation",
        "Projected Cost": 500,
        "Actual Cost": 500,
        "Difference": 0,
    },
    {
        "Expense Type": "Insurance",
        "Projected Cost": 1000,
        "Actual Cost": 1000,
        "Difference": 0,
    },
    {
        "Expense Type": "Food",
        "Projected Cost": 2000,
        "Actual Cost": 1800,
        "Difference": 200,
    },
    {
        "Expense Type": "Pets",
        "Projected Cost": 300,
        "Actual Cost": 200,
        "Difference": 100,
    },
    {
        "Expense Type": "Personel Care",
        "Projected Cost": 500,
        "Actual Cost": 500,
        "Difference": 0,
    }, {
        "Expense Type": "Loan",
        "Projected Cost": 1000,
        "Actual Cost": 1000,
        "Difference": 0,
    }, {
        "Expense Type": "Tax",
        "Projected Cost": 200,
        "Actual Cost": 200,
        "Difference": 0,
    }, {
        "Expense Type": "Savings",
        "Projected Cost": 1000,
        "Actual Cost": 900,
        "Difference": 100,
    },
    {
        "Expense Type": "Total",
        "Projected Cost": 13500,
        "Actual Cost": 13600,
        "Difference": -100,
    }
];
export let salaryData = [
    {
        "Earnings": "Basic",
        "Credit Amount": 20000,
        "Deductions": "Provident Fund",
        "Debit Amount": 2400,
    },
    {
        "Earnings": "HRA",
        "Credit Amount": 8000,
        "Deductions": "ESI",
        "Debit Amount": 0,
    },
    {
        "Earnings": "Special Allowance",
        "Credit Amount": 25000,
        "Deductions": "Professional Tax",
        "Debit Amount": 200,
    },
    {
        "Earnings": "Incentives",
        "Credit Amount": 2000,
        "Deductions": "TDS",
        "Debit Amount": 2750,
    },
    {
        "Earnings": "Bonus",
        "Credit Amount": 1500,
        "Deductions": "Other Deduction",
        "Debit Amount": 0,
    },
    {
        "Earnings": "Total Earnings",
        "Credit Amount": 56500,
        "Deductions": "Total Deductions",
        "Debit Amount": 5350,
    }
];
export let budgetData: Object[] = [
    {
      "Expense Type": "Housing",
      "Projected Cost": 7000,
      "Actual Cost": 7500,
      "Difference": -500,
    },
    {
      "Expense Type": "Transportation",
      "Projected Cost": 500,
      "Actual Cost": 500,
      "Difference": 0,
    },
    {
      "Expense Type": "Insurance",
      "Projected Cost": 1000,
      "Actual Cost": 1000,
      "Difference": 0,
    },
    {
      "Expense Type": "Food",
      "Projected Cost": 2000,
      "Actual Cost": 1800,
      "Difference": 200,
    },
    {
      "Expense Type": "Pets",
      "Projected Cost": 300,
      "Actual Cost": 200,
      "Difference": 100,
    },
    {
      "Expense Type": "Personel Care",
      "Projected Cost": 500,
      "Actual Cost": 500,
      "Difference": 0,
    },{
      "Expense Type": "Loan",
      "Projected Cost": 1000,
      "Actual Cost": 1000,
      "Difference": 0,
    },{
      "Expense Type": "Tax",
      "Projected Cost": 200,
      "Actual Cost": 200,
      "Difference": 0,
    },{
      "Expense Type": "Savings",
      "Projected Cost": 1000,
      "Actual Cost": 900,
      "Difference": 100,
    },
    {
      "Expense Type": "Total",
      "Projected Cost": 13500,
      "Actual Cost": 13600,
      "Difference": -100,
    }
  ]

  export let salaryData: Object[] = [
    {
      "Earnings": "Basic",
      "Credit Amount": 20000,
      "Deductions": "Provident Fund",
      "Debit Amount": 2400,
    },
    {
      "Earnings": "HRA",
      "Credit Amount": 8000,
      "Deductions": "ESI",
      "Debit Amount": 0,
    },
    {
      "Earnings": "Special Allowance",
      "Credit Amount": 25000,
      "Deductions": "Professional Tax",
      "Debit Amount": 200,
    },
    {
      "Earnings": "Incentives",
      "Credit Amount": 2000,
      "Deductions": "TDS",
      "Debit Amount": 2750,
    },
    {
      "Earnings": "Bonus",
      "Credit Amount": 1500,
      "Deductions": "Other Deduction",
      "Debit Amount": 0,
    },
    {
      "Earnings": "Total Earnings",
      "Credit Amount": 56500,
      "Deductions": "Total Deductions",
      "Debit Amount": 5350,
    }
  ]

Limitations of Protect sheet

  • Password encryption is not supported

Unprotect Sheet

Unprotect sheet is used to enable all the functionalities that are already disabled in a protected spreadsheet.

User Interface:

In the active Spreadsheet, the sheet Unprotection can be done by any of the following ways:

  • Select the Unprotect Sheet item in the Ribbon toolbar under the Data Tab.
  • Right-click the sheet tab, select the Unprotect Sheet item in the context menu.
  • Use the unprotectSheet() method programmatically.

Unlock the particular cells in the protected sheet

In protected spreadsheet, to make some particular cell or range of cells are editable, you can use lockCells() method, with the parameter range and isLocked property as false.

import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective, ColumnsDirective, ColumnDirective, RangeDirective } from '@syncfusion/ej2-react-spreadsheet';
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import { budgetData, salaryData } from './datasource';

function App() {
    const spreadsheetRef = React.useRef(null);
    const dialogRef = React.useRef(null);
    React.useEffect(() => {
        let spreadsheet = spreadsheetRef.current;
        if (spreadsheet) {
            spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
            spreadsheet.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
        }
    }, []);
    const lockCells = () => {
        let spreadsheet = spreadsheetRef.current;
        let dialog = dialogRef.current;
        if (spreadsheet) {
            spreadsheet.lockCells('A1:F3', false);
        }
        if (dialog) {
            dialog.hide();
        }
    };
    const showDlg = () => {
        let dialog = dialogRef.current;
        if (dialog) {
            dialog.show();
        }
    };
    const protectSettings = { selectCells: true };
    const btn = [{ click: lockCells, buttonModel: { content: 'Ok', isPrimary: true } }];

    return (
        <div>
            <button onClick={showDlg}>Unlock cells</button>
            <SpreadsheetComponent ref={spreadsheetRef}>
                <SheetsDirective>
                    <SheetDirective name={"Budget"} isProtected={true} protectSettings={protectSettings}>
                        <RangesDirective>
                            <RangeDirective dataSource={budgetData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                    <SheetDirective name={"Salary"}>
                        <RangesDirective>
                            <RangeDirective dataSource={salaryData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                </SheetsDirective>
            </SpreadsheetComponent>
            <DialogComponent ref={dialogRef} header={'Spreadsheet'} target={document.getElementById('spreadsheet')} content={'"A1:F3" range of cells has been unlocked.'}
                showCloseIcon={true} isModal={true} visible={false} width={'500px'} buttons={btn}>
            </DialogComponent>
        </div>
    );
};
export default App;

const root = createRoot(document.getElementById('root'));
root.render(<App />);
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective, ColumnsDirective, ColumnDirective, RangeDirective } from '@syncfusion/ej2-react-spreadsheet';
import { ButtonPropsModel, DialogComponent } from '@syncfusion/ej2-react-popups';
import { budgetData, salaryData } from './datasource';

function App() {
    const spreadsheetRef = React.useRef<SpreadsheetComponent>(null);
    const dialogRef = React.useRef<DialogComponent>(null);
    React.useEffect(() => {
        let spreadsheet = spreadsheetRef.current;
        if (spreadsheet) {
            spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
            spreadsheet.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
        }
    }, []);
    const lockCells = (): void => {
        let spreadsheet = spreadsheetRef.current;
        let dialog = dialogRef.current;
        if (spreadsheet) {
            spreadsheet.lockCells('A1:F3', false);
        }
        if (dialog) {
            dialog.hide();
        }
    };
    const showDlg = (): void => {
        let dialog = dialogRef.current;
        if (dialog) {
            dialog.show();
        }
    };
    const protectSettings = { selectCells: true };
    const btn: ButtonPropsModel[] = [{ click: lockCells, buttonModel: { content: 'Ok', isPrimary: true } }];

    return (
        <div>
            <button onClick={showDlg}>Unlock cells</button>
            <SpreadsheetComponent ref={spreadsheetRef}>
                <SheetsDirective>
                    <SheetDirective name={"Budget"} isProtected={true} protectSettings={protectSettings}>
                        <RangesDirective>
                            <RangeDirective dataSource={budgetData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                    <SheetDirective name={"Salary"}>
                        <RangesDirective>
                            <RangeDirective dataSource={salaryData}></RangeDirective>
                        </RangesDirective>
                        <ColumnsDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                            <ColumnDirective width={100}></ColumnDirective>
                        </ColumnsDirective>
                    </SheetDirective>
                </SheetsDirective>
            </SpreadsheetComponent>
            <DialogComponent ref={dialogRef} header={'Spreadsheet'} target={document.getElementById('spreadsheet') as HTMLElement} content={'"A1:F3" range of cells has been unlocked.'}
                showCloseIcon={true} isModal={true} visible={false} width={'500px'} buttons={btn}>
            </DialogComponent>
        </div>
    );
};
export default App;

const root = createRoot(document.getElementById('root')!);
root.render(<App />);
export let budgetData = [
    {
        "Expense Type": "Housing",
        "Projected Cost": 7000,
        "Actual Cost": 7500,
        "Difference": -500,
    },
    {
        "Expense Type": "Transportation",
        "Projected Cost": 500,
        "Actual Cost": 500,
        "Difference": 0,
    },
    {
        "Expense Type": "Insurance",
        "Projected Cost": 1000,
        "Actual Cost": 1000,
        "Difference": 0,
    },
    {
        "Expense Type": "Food",
        "Projected Cost": 2000,
        "Actual Cost": 1800,
        "Difference": 200,
    },
    {
        "Expense Type": "Pets",
        "Projected Cost": 300,
        "Actual Cost": 200,
        "Difference": 100,
    },
    {
        "Expense Type": "Personel Care",
        "Projected Cost": 500,
        "Actual Cost": 500,
        "Difference": 0,
    }, {
        "Expense Type": "Loan",
        "Projected Cost": 1000,
        "Actual Cost": 1000,
        "Difference": 0,
    }, {
        "Expense Type": "Tax",
        "Projected Cost": 200,
        "Actual Cost": 200,
        "Difference": 0,
    }, {
        "Expense Type": "Savings",
        "Projected Cost": 1000,
        "Actual Cost": 900,
        "Difference": 100,
    },
    {
        "Expense Type": "Total",
        "Projected Cost": 13500,
        "Actual Cost": 13600,
        "Difference": -100,
    }
];
export let salaryData = [
    {
        "Earnings": "Basic",
        "Credit Amount": 20000,
        "Deductions": "Provident Fund",
        "Debit Amount": 2400,
    },
    {
        "Earnings": "HRA",
        "Credit Amount": 8000,
        "Deductions": "ESI",
        "Debit Amount": 0,
    },
    {
        "Earnings": "Special Allowance",
        "Credit Amount": 25000,
        "Deductions": "Professional Tax",
        "Debit Amount": 200,
    },
    {
        "Earnings": "Incentives",
        "Credit Amount": 2000,
        "Deductions": "TDS",
        "Debit Amount": 2750,
    },
    {
        "Earnings": "Bonus",
        "Credit Amount": 1500,
        "Deductions": "Other Deduction",
        "Debit Amount": 0,
    },
    {
        "Earnings": "Total Earnings",
        "Credit Amount": 56500,
        "Deductions": "Total Deductions",
        "Debit Amount": 5350,
    }
];
export let budgetData: Object[] = [
    {
      "Expense Type": "Housing",
      "Projected Cost": 7000,
      "Actual Cost": 7500,
      "Difference": -500,
    },
    {
      "Expense Type": "Transportation",
      "Projected Cost": 500,
      "Actual Cost": 500,
      "Difference": 0,
    },
    {
      "Expense Type": "Insurance",
      "Projected Cost": 1000,
      "Actual Cost": 1000,
      "Difference": 0,
    },
    {
      "Expense Type": "Food",
      "Projected Cost": 2000,
      "Actual Cost": 1800,
      "Difference": 200,
    },
    {
      "Expense Type": "Pets",
      "Projected Cost": 300,
      "Actual Cost": 200,
      "Difference": 100,
    },
    {
      "Expense Type": "Personel Care",
      "Projected Cost": 500,
      "Actual Cost": 500,
      "Difference": 0,
    },{
      "Expense Type": "Loan",
      "Projected Cost": 1000,
      "Actual Cost": 1000,
      "Difference": 0,
    },{
      "Expense Type": "Tax",
      "Projected Cost": 200,
      "Actual Cost": 200,
      "Difference": 0,
    },{
      "Expense Type": "Savings",
      "Projected Cost": 1000,
      "Actual Cost": 900,
      "Difference": 100,
    },
    {
      "Expense Type": "Total",
      "Projected Cost": 13500,
      "Actual Cost": 13600,
      "Difference": -100,
    }
  ]

  export let salaryData: Object[] = [
    {
      "Earnings": "Basic",
      "Credit Amount": 20000,
      "Deductions": "Provident Fund",
      "Debit Amount": 2400,
    },
    {
      "Earnings": "HRA",
      "Credit Amount": 8000,
      "Deductions": "ESI",
      "Debit Amount": 0,
    },
    {
      "Earnings": "Special Allowance",
      "Credit Amount": 25000,
      "Deductions": "Professional Tax",
      "Debit Amount": 200,
    },
    {
      "Earnings": "Incentives",
      "Credit Amount": 2000,
      "Deductions": "TDS",
      "Debit Amount": 2750,
    },
    {
      "Earnings": "Bonus",
      "Credit Amount": 1500,
      "Deductions": "Other Deduction",
      "Debit Amount": 0,
    },
    {
      "Earnings": "Total Earnings",
      "Credit Amount": 56500,
      "Deductions": "Total Deductions",
      "Debit Amount": 5350,
    }
  ]

Protect Workbook

Protect workbook feature helps you to protect the workbook so that users cannot insert, delete, rename, hide the sheets in the spreadsheet. You can use the password property to protect workbook with password. You can use the isProtected property to protect or unprotect the workbook without the password.

The default value for isProtected property is false.

User Interface:

In the active Spreadsheet, you can protect the worksheet by selecting the Data tab in the Ribbon toolbar and choosing the Protect Workbook item. Then, enter the password and confirm it and click on OK.

The following example shows Protect Workbook by using the isProtected property in the Spreadsheet control.

import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective } from '@syncfusion/ej2-react-spreadsheet';
import { RangeDirective, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-spreadsheet';
import { data } from './datasource';

function App() {
    return (
        <SpreadsheetComponent isProtected={true}>
            <SheetsDirective>
                <SheetDirective>
                    <RangesDirective>
                        <RangeDirective dataSource={data}></RangeDirective>
                    </RangesDirective>
                    <ColumnsDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={110}></ColumnDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={180}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                    </ColumnsDirective>
                </SheetDirective>
            </SheetsDirective>
        </SpreadsheetComponent>
    );
};
export default App;

const root = createRoot(document.getElementById('root'));
root.render(<App />);
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective } from '@syncfusion/ej2-react-spreadsheet';
import { RangeDirective, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-spreadsheet';
import { data } from './datasource';

function App() {
    return (
        <SpreadsheetComponent isProtected={true}>
            <SheetsDirective>
                <SheetDirective>
                    <RangesDirective>
                        <RangeDirective dataSource={data}></RangeDirective>
                    </RangesDirective>
                    <ColumnsDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={110}></ColumnDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={180}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                    </ColumnsDirective>
                </SheetDirective>
            </SheetsDirective>
        </SpreadsheetComponent>
    );
};
export default App;

const root = createRoot(document.getElementById('root')!);
root.render(<App />);
/**
 * Default data source
 */
export let data = [{
        OrderID: 10248,
        CustomerID: 'VINET',
        EmployeeID: 5,
        ShipName: 'Vins et alcools Chevalier',
        ShipCity: 'Reims',
        ShipAddress: '59 rue de lAbbaye'
    },
    {
        OrderID: 10249,
        CustomerID: 'TOMSP',
        EmployeeID: 6,
        ShipName: 'Toms Spezialitäten',
        ShipCity: 'Münster',
        ShipAddress: 'Luisenstr. 48'
    },
    {
        OrderID: 10250,
        CustomerID: 'HANAR',
        EmployeeID: 4,
        ShipName: 'Hanari Carnes',
        ShipCity: 'Rio de Janeiro',
        ShipAddress: 'Rua do Paço, 67'
    },
    {
        OrderID: 10251,
        CustomerID: 'VICTE',
        EmployeeID: 3,
        ShipName: 'Victuailles en stock',
        ShipCity: 'Lyon',
        ShipAddress: '2, rue du Commerce'
    },
    {
        OrderID: 10252,
        CustomerID: 'SUPRD',
        EmployeeID: 4,
        ShipName: 'Suprêmes délices',
        ShipCity: 'Charleroi',
        ShipAddress: 'Boulevard Tirou, 255'
    }];
/**
 * Default data source
 */
export let data: Object[]  = [{
  OrderID: 10248,
  CustomerID: 'VINET',
  EmployeeID: 5,
  ShipName: 'Vins et alcools Chevalier',
  ShipCity: 'Reims',
  ShipAddress: '59 rue de lAbbaye'
},
{
  OrderID: 10249,
  CustomerID: 'TOMSP',
  EmployeeID: 6,
  ShipName: 'Toms Spezialitäten',
  ShipCity: 'Münster',
  ShipAddress: 'Luisenstr. 48'
},
{
  OrderID: 10250,
  CustomerID: 'HANAR',
  EmployeeID: 4,
  ShipName: 'Hanari Carnes',
  ShipCity: 'Rio de Janeiro',
  ShipAddress: 'Rua do Paço, 67'
},
{
  OrderID: 10251,
  CustomerID: 'VICTE',
  EmployeeID: 3,
  ShipName: 'Victuailles en stock',
  ShipCity: 'Lyon',
  ShipAddress: '2, rue du Commerce'
},
{
  OrderID: 10252,
  CustomerID: 'SUPRD',
  EmployeeID: 4,
  ShipName: 'Suprêmes délices',
  ShipCity: 'Charleroi',
  ShipAddress: 'Boulevard Tirou, 255'
}];

The following example shows Protect Workbook by using the password property in the Spreadsheet control. To unprotect the workbook, click the unprotect workbook button in the data tab and provide the password as syncfusion in the dialog box.

import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective } from '@syncfusion/ej2-react-spreadsheet';
import { RangeDirective, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-spreadsheet';
import { data } from './datasource';

function App() {
    return (
        <SpreadsheetComponent password='syncfusion' >
            <SheetsDirective>
                <SheetDirective>
                    <RangesDirective>
                        <RangeDirective dataSource={data}></RangeDirective>
                    </RangesDirective>
                    <ColumnsDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={110}></ColumnDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={180}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                    </ColumnsDirective>
                </SheetDirective>
            </SheetsDirective>
        </SpreadsheetComponent>
    );
};
export default App;

const root = createRoot(document.getElementById('root'));
root.render(<App />);
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective } from '@syncfusion/ej2-react-spreadsheet';
import { RangeDirective, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-spreadsheet';
import { data } from './datasource';

function App() {
    return (
        <SpreadsheetComponent password='syncfusion' >
            <SheetsDirective>
                <SheetDirective>
                    <RangesDirective>
                        <RangeDirective dataSource={data}></RangeDirective>
                    </RangesDirective>
                    <ColumnsDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={110}></ColumnDirective>
                        <ColumnDirective width={100}></ColumnDirective>
                        <ColumnDirective width={180}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                        <ColumnDirective width={130}></ColumnDirective>
                    </ColumnsDirective>
                </SheetDirective>
            </SheetsDirective>
        </SpreadsheetComponent>
    );
};
export default App;

const root = createRoot(document.getElementById('root')!);
root.render(<App />);
/**
 * Default data source
 */
export let data = [{
        OrderID: 10248,
        CustomerID: 'VINET',
        EmployeeID: 5,
        ShipName: 'Vins et alcools Chevalier',
        ShipCity: 'Reims',
        ShipAddress: '59 rue de lAbbaye'
    },
    {
        OrderID: 10249,
        CustomerID: 'TOMSP',
        EmployeeID: 6,
        ShipName: 'Toms Spezialitäten',
        ShipCity: 'Münster',
        ShipAddress: 'Luisenstr. 48'
    },
    {
        OrderID: 10250,
        CustomerID: 'HANAR',
        EmployeeID: 4,
        ShipName: 'Hanari Carnes',
        ShipCity: 'Rio de Janeiro',
        ShipAddress: 'Rua do Paço, 67'
    },
    {
        OrderID: 10251,
        CustomerID: 'VICTE',
        EmployeeID: 3,
        ShipName: 'Victuailles en stock',
        ShipCity: 'Lyon',
        ShipAddress: '2, rue du Commerce'
    },
    {
        OrderID: 10252,
        CustomerID: 'SUPRD',
        EmployeeID: 4,
        ShipName: 'Suprêmes délices',
        ShipCity: 'Charleroi',
        ShipAddress: 'Boulevard Tirou, 255'
    }];
/**
 * Default data source
 */
export let data: Object[]  = [{
  OrderID: 10248,
  CustomerID: 'VINET',
  EmployeeID: 5,
  ShipName: 'Vins et alcools Chevalier',
  ShipCity: 'Reims',
  ShipAddress: '59 rue de lAbbaye'
},
{
  OrderID: 10249,
  CustomerID: 'TOMSP',
  EmployeeID: 6,
  ShipName: 'Toms Spezialitäten',
  ShipCity: 'Münster',
  ShipAddress: 'Luisenstr. 48'
},
{
  OrderID: 10250,
  CustomerID: 'HANAR',
  EmployeeID: 4,
  ShipName: 'Hanari Carnes',
  ShipCity: 'Rio de Janeiro',
  ShipAddress: 'Rua do Paço, 67'
},
{
  OrderID: 10251,
  CustomerID: 'VICTE',
  EmployeeID: 3,
  ShipName: 'Victuailles en stock',
  ShipCity: 'Lyon',
  ShipAddress: '2, rue du Commerce'
},
{
  OrderID: 10252,
  CustomerID: 'SUPRD',
  EmployeeID: 4,
  ShipName: 'Suprêmes délices',
  ShipCity: 'Charleroi',
  ShipAddress: 'Boulevard Tirou, 255'
}];

Unprotect Workbook

Unprotect Workbook is used to enable the insert, delete, rename, move, copy, hide or unhide sheets feature in the spreadsheet.

User Interface:

In the active Spreadsheet, the workbook Unprotection can be done in any of the following ways:

  • Select the Unprotect Workbook item in the Ribbon toolbar under the Data Tab and provide the valid password in the dialog box.

Note

You can refer to our React Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our React Spreadsheet example to knows how to present and manipulate data.

See Also