Excel Export allows you to protect the exported worksheet so that users can only edit specific cells.
Data Protection Copy Link
Excel has two layers of protection:
- Cell Protection controls whether a cell is locked and whether a formula is hidden (
ExcelStyle.protection). - Worksheet Protection enables enforcement of the locked/unlocked cell states (
ExcelExportParams.protectSheet).
Cell locking only takes effect when the worksheet is protected. If you lock cells but do not enable worksheet protection, all cells will remain editable in Excel.
Enable worksheet protection by setting protectSheet in the Excel Export Params (or in defaultExcelExportParams):
const defaultExcelExportParams = useMemo(() => {
return {
protectSheet: true
};
}, []);
<AgGridReact defaultExcelExportParams={defaultExcelExportParams} /> Worksheet Custom Protection Copy Link
To allow specific actions, or to require a password to unprotect the sheet, provide an ExcelSheetProtection config object:
const defaultExcelExportParams = useMemo(() => {
return {
protectSheet: {
password: 'secret',
autoFilter: true,
formatCells: true
}
};
}, []);
<AgGridReact defaultExcelExportParams={defaultExcelExportParams} />Excel uses an obfuscation algorithm for worksheet protection passwords. It should not be treated as strong security.
Unlocking Cells Copy Link
When worksheet protection is enabled, all exported cells are locked by default. To unlock specific cells or columns, configure an Excel style with protection.protected = false and apply that style via cellClass / cellClassRules:
const [columnDefs, setColumnDefs] = useState([
{ field: 'athlete', cellClass: 'unlocked' },
{ field: 'country', cellClass: 'unlocked' }
]);
const excelStyles = useMemo(() => {
return [
{
id: 'unlocked',
protection: { protected: false, hideFormula: false }
}
];
}, []);
const defaultExcelExportParams = useMemo(() => {
return {
protectSheet: true
};
}, []);
<AgGridReact
columnDefs={columnDefs}
excelStyles={excelStyles}
defaultExcelExportParams={defaultExcelExportParams}
/> Interfaces Copy Link
ExcelExportParams Copy Link
interface ExcelExportParams {
// ...
protectSheet?: boolean | ExcelSheetProtection;
}
ExcelSheetProtection Copy Link
Properties available on the ExcelSheetProtection interface.
Allow using AutoFilter when worksheet protection is enabled. |
Allow deleting columns when worksheet protection is enabled. |
Allow deleting rows when worksheet protection is enabled. |
Allow formatting cells when worksheet protection is enabled. |
Allow formatting columns when worksheet protection is enabled. |
Allow formatting rows when worksheet protection is enabled. |
Allow inserting columns when worksheet protection is enabled. |
Allow inserting hyperlinks when worksheet protection is enabled. |
Allow inserting rows when worksheet protection is enabled. |
Allow using PivotTables when worksheet protection is enabled. |
Allow selecting locked cells when worksheet protection is enabled. |
Allow selecting unlocked cells when worksheet protection is enabled. |
Optional password required to unprotect the worksheet.
|
ExcelStyle Copy Link
interface ExcelStyle {
// ...
protection?: ExcelProtection;
}
ExcelProtection Copy Link
Properties available on the ExcelProtection interface.
Set to false to disable cell protection (locking) |
Set to true to hide formulas within protected cells. |
Next Up Copy Link
Continue to the next section: API Reference.