---
product: "AG Grid"
title: "Excel Export - Data Protection"
description: "Excel Export allows you to protect the exported worksheet so that users can only edit specific cells."
enterprise: true
framework: javascript
version: "36.2.0"
related:
    - title: "Styles"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-styles/"
    - title: "Formulas"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-formulas/"
    - title: "Extra Content"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-extra-content/"
    - title: "Notes"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-notes/"
    - title: "Customising Content"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-customising-content/"
    - title: "Images"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-images/"
    - title: "Excel Tables"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-tables/"
    - title: "Multiple Sheets"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-multiple-sheets/"
    - title: "Rows"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-rows/"
    - title: "Columns"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-columns/"
    - title: "Freezing Content"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-freeze/"
    - title: "Data Types"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-data-types/"
    - title: "Hyperlinks"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-hyperlinks/"
    - title: "Master Detail"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-master-detail/"
    - title: "Page Setup"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-page-setup/"
    - title: "API Reference"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-api/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Excel Export - Data Protection

Excel Export allows you to protect the exported worksheet so that users can only edit specific cells.

## Data Protection

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`).

> **Note**
>
> 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](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/excel-export-api/#excelexportparams) (or in `defaultExcelExportParams`):

```js
const gridOptions = {
    defaultExcelExportParams: {
        protectSheet: true
    },

    // other grid options ...
}
```

#### Excel Export - Data Protection (Default)

```ts
import {
  ClientSideRowModelModule,
  CsvExportModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  ExcelExportModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

if (process.env.NODE_ENV !== "production") {
  // Enable extended validations only for development
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  ClientSideRowModelModule,
  CsvExportModule,
  ExcelExportModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", minWidth: 200 },
    { field: "country", minWidth: 180 },
    { field: "sport", minWidth: 150 },
    { field: "gold", width: 100 },
    { field: "silver", width: 100 },
    { field: "bronze", width: 100 },
    { field: "total", width: 100 },
  ],
  defaultColDef: {
    filter: true,
    minWidth: 100,
    flex: 1,
  },
  defaultExcelExportParams: {
    protectSheet: true,
  },
};

function onBtExport() {
  gridApi!.exportDataAsExcel();
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then(function (data) {
    gridApi!.setGridOption("rowData", data);
  });

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).onBtExport = onBtExport;
}
```

[Live example: Excel Export - Data Protection (Default)](https://www.ag-grid.com/archive/36.2.0/examples/excel-export-data-protection/excel-export-data-protection-default/typescript/)

## Worksheet Custom Protection

To allow specific actions, or to require a password to unprotect the sheet, provide an `ExcelSheetProtection` config object:

```js
const gridOptions = {
    defaultExcelExportParams: {
        protectSheet: {
            password: 'secret',
            autoFilter: true,
            formatCells: true
        }
    },

    // other grid options ...
}
```

#### Excel Export - Data Protection (Custom Sheet Protection)

```ts
import {
  ClientSideRowModelModule,
  CsvExportModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  ExcelExportModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

if (process.env.NODE_ENV !== "production") {
  // Enable extended validations only for development
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  ClientSideRowModelModule,
  CsvExportModule,
  ExcelExportModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

let gridApi: GridApi<IOlympicData>;

const isChecked = (selector: string): boolean =>
  document.querySelector<HTMLInputElement>(selector)?.checked ?? false;
const getInputValue = (selector: string): string =>
  document.querySelector<HTMLInputElement>(selector)?.value ?? "";

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", minWidth: 200 },
    { field: "country", minWidth: 180 },
    { field: "sport", minWidth: 150 },
    { field: "gold", width: 100 },
    { field: "silver", width: 100 },
    { field: "bronze", width: 100 },
    { field: "total", width: 100 },
  ],
  defaultColDef: {
    filter: true,
    minWidth: 100,
    flex: 1,
  },
};

function onBtExport() {
  const password = getInputValue("#worksheetPassword").trim() || undefined;
  const autoFilter = isChecked("#allowAutoFilter");
  const formatCells = isChecked("#allowFormatCells");

  gridApi!.exportDataAsExcel({
    protectSheet: {
      password,
      autoFilter,
      formatCells,
    },
  });
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then(function (data) {
    gridApi!.setGridOption("rowData", data);
  });

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).onBtExport = onBtExport;
}
```

[Live example: Excel Export - Data Protection (Custom Sheet Protection)](https://www.ag-grid.com/archive/36.2.0/examples/excel-export-data-protection/excel-export-data-protection-custom/typescript/)

> **Note**
>
> Excel uses an obfuscation algorithm for worksheet protection passwords. It should not be treated as strong security.

## Unlocking Cells

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`:

```js
const gridOptions = {
    columnDefs: [
        { field: 'athlete', cellClass: 'unlocked' },
        { field: 'country', cellClass: 'unlocked' }
    ],
    excelStyles: [
        {
            id: 'unlocked',
            protection: { protected: false, hideFormula: false }
        }
    ],
    defaultExcelExportParams: {
        protectSheet: true
    },

    // other grid options ...
}
```

#### Excel Export - Data Protection (Unlocking Cells)

```ts
import {
  CellStyleModule,
  ClientSideRowModelModule,
  CsvExportModule,
  ExcelStyle,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  TextEditorModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  ExcelExportModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

if (process.env.NODE_ENV !== "production") {
  // Enable extended validations only for development
  enableDevValidations();
}

ModuleRegistry.registerModules([
  CellStyleModule,
  TextFilterModule,
  TextEditorModule,
  NumberFilterModule,
  ClientSideRowModelModule,
  CsvExportModule,
  ExcelExportModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

let gridApi: GridApi<IOlympicData>;

const excelStyles: ExcelStyle[] = [
  {
    id: "unlocked",
    interior: {
      color: "#C6EFCE",
      pattern: "Solid",
    },
    protection: {
      protected: false,
      hideFormula: false,
    },
  },
];

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    {
      headerName: "Editable (Unlocked)",
      children: [
        {
          field: "athlete",
          minWidth: 200,
          cellClass: "unlocked",
          editable: true,
        },
        {
          field: "country",
          minWidth: 200,
          cellClass: "unlocked",
          editable: true,
        },
      ],
    },
    {
      headerName: "Read Only (Locked)",
      children: [
        { field: "sport", minWidth: 150 },
        { field: "gold" },
        { field: "silver" },
        { field: "bronze" },
        { field: "total" },
      ],
    },
  ],
  defaultColDef: {
    filter: true,
    minWidth: 100,
    flex: 1,
  },
  excelStyles,
  defaultExcelExportParams: {
    protectSheet: true,
  },
};

function onBtExport() {
  gridApi!.exportDataAsExcel();
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then(function (data) {
    gridApi!.setGridOption("rowData", data);
  });

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).onBtExport = onBtExport;
}
```

[Live example: Excel Export - Data Protection (Unlocking Cells)](https://www.ag-grid.com/archive/36.2.0/examples/excel-export-data-protection/excel-export-unlocking-cells/typescript/)

## Interfaces

### ExcelExportParams

```ts
interface ExcelExportParams {
    // ...
    protectSheet?: boolean | ExcelSheetProtection;
}
```

### ExcelSheetProtection

Properties available on the `ExcelSheetProtection` interface.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `autoFilter` | `boolean` |  |  |  |
| `deleteColumns` | `boolean` |  |  |  |
| `deleteRows` | `boolean` |  |  |  |
| `formatCells` | `boolean` |  |  |  |
| `formatColumns` | `boolean` |  |  |  |
| `formatRows` | `boolean` |  |  |  |
| `insertColumns` | `boolean` |  |  |  |
| `insertHyperlinks` | `boolean` |  |  |  |
| `insertRows` | `boolean` |  |  |  |
| `pivotTables` | `boolean` |  |  |  |
| `selectLockedCells` | `boolean` |  |  |  |
| `selectUnlockedCells` | `boolean` |  |  |  |
| `password` | `string` |  |  |  |

### ExcelStyle

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

### ExcelProtection

Properties available on the `ExcelProtection` interface.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `protected` | `boolean` |  |  |  |
| `hideFormula` | `boolean` |  |  |  |
