Advanced Features

React Data GridExcel Export - Data Protection

Enterprise

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:

  1. Cell Protection controls whether a cell is locked and whether a formula is hidden (ExcelStyle.protection).
  2. 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.

autoFilterCopy Link
boolean
default: false
Allow using AutoFilter when worksheet protection is enabled.
deleteColumnsCopy Link
boolean
default: false
Allow deleting columns when worksheet protection is enabled.
deleteRowsCopy Link
boolean
default: false
Allow deleting rows when worksheet protection is enabled.
formatCellsCopy Link
boolean
default: false
Allow formatting cells when worksheet protection is enabled.
formatColumnsCopy Link
boolean
default: false
Allow formatting columns when worksheet protection is enabled.
formatRowsCopy Link
boolean
default: false
Allow formatting rows when worksheet protection is enabled.
insertColumnsCopy Link
boolean
default: false
Allow inserting columns when worksheet protection is enabled.
boolean
default: false
Allow inserting hyperlinks when worksheet protection is enabled.
insertRowsCopy Link
boolean
default: false
Allow inserting rows when worksheet protection is enabled.
pivotTablesCopy Link
boolean
default: false
Allow using PivotTables when worksheet protection is enabled.
selectLockedCellsCopy Link
boolean
default: true
Allow selecting locked cells when worksheet protection is enabled.
selectUnlockedCellsCopy Link
boolean
default: true
Allow selecting unlocked cells when worksheet protection is enabled.
passwordCopy Link
string
Optional password required to unprotect the worksheet.

ExcelStyle Copy Link

interface ExcelStyle {
    // ...
    protection?: ExcelProtection;
}

ExcelProtection Copy Link

Properties available on the ExcelProtection interface.

protectedCopy Link
boolean
default: true
Set to false to disable cell protection (locking)
hideFormulaCopy Link
boolean
default: false
Set to true to hide formulas within protected cells.

Next Up Copy Link

Continue to the next section: API Reference.