---
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: vue
version: "36.2.0"
related:
    - title: "Styles"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-styles/"
    - title: "Formulas"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-formulas/"
    - title: "Extra Content"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-extra-content/"
    - title: "Notes"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-notes/"
    - title: "Customising Content"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-customising-content/"
    - title: "Images"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-images/"
    - title: "Excel Tables"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-tables/"
    - title: "Multiple Sheets"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-multiple-sheets/"
    - title: "Rows"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-rows/"
    - title: "Columns"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-columns/"
    - title: "Freezing Content"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-freeze/"
    - title: "Data Types"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-data-types/"
    - title: "Hyperlinks"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-hyperlinks/"
    - title: "Master Detail"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-master-detail/"
    - title: "Page Setup"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-data-grid/excel-export-page-setup/"
    - title: "API Reference"
      url: "https://www.ag-grid.com/archive/36.2.0/vue-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/vue-data-grid/excel-export-api/#excelexportparams) (or in `defaultExcelExportParams`):

```ts
<ag-grid-vue
    :defaultExcelExportParams="defaultExcelExportParams"
    /* other grid options ... */>
</ag-grid-vue>

this.defaultExcelExportParams = {
    protectSheet: true
};
```

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

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  CsvExportModule,
  ExcelExportParams,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  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,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="container">
      <div class="controls">
        <button v-on:click="onBtExport()" style="margin-bottom: 5px; font-weight: bold">Export to Excel</button>
      </div>
      <div class="grid-wrapper">
        <ag-grid-vue
          style="width: 100%; height: 100%;"
          @grid-ready="onGridReady"
          :columnDefs="columnDefs"
          :defaultColDef="defaultColDef"
          :defaultExcelExportParams="defaultExcelExportParams"
          :rowData="rowData"></ag-grid-vue>
        </div>
      </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IOlympicData> | null>(null);
    const columnDefs = ref<ColDef[]>([
      { 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 },
    ]);
    const defaultColDef = ref<ColDef>({
      filter: true,
      minWidth: 100,
      flex: 1,
    });
    const defaultExcelExportParams = ref<ExcelExportParams>({
      protectSheet: true,
    });
    const rowData = ref<IOlympicData[]>(null);

    function onBtExport() {
      gridApi.value!.exportDataAsExcel();
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        rowData.value = data;
      };

      fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      defaultExcelExportParams,
      rowData,
      onGridReady,
      onBtExport,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[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/vue3/)

## Worksheet Custom Protection

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

```ts
<ag-grid-vue
    :defaultExcelExportParams="defaultExcelExportParams"
    /* other grid options ... */>
</ag-grid-vue>

this.defaultExcelExportParams = {
    protectSheet: {
        password: 'secret',
        autoFilter: true,
        formatCells: true
    }
};
```

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

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  CsvExportModule,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  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,
]);

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

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

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="container">
      <div class="controls">
        <label class="option">
          Worksheet password (optional):
          <input type="text" id="worksheetPassword" value="secret">
          </label>
          <label class="option">
            <input type="checkbox" id="allowAutoFilter">
              Allow filtering (autoFilter)
            </label>
            <label class="option">
              <input type="checkbox" id="allowFormatCells">
                Allow formatting cells (formatCells)
              </label>
              <button v-on:click="onBtExport()" style="margin-bottom: 5px; font-weight: bold">Export to Excel</button>
            </div>
            <div class="grid-wrapper">
              <ag-grid-vue
                style="width: 100%; height: 100%;"
                @grid-ready="onGridReady"
                :columnDefs="columnDefs"
                :defaultColDef="defaultColDef"
                :rowData="rowData"></ag-grid-vue>
              </div>
            </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IOlympicData> | null>(null);
    const columnDefs = ref<ColDef[]>([
      { 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 },
    ]);
    const defaultColDef = ref<ColDef>({
      filter: true,
      minWidth: 100,
      flex: 1,
    });
    const rowData = ref<IOlympicData[]>(null);

    function onBtExport() {
      const password = getInputValue("#worksheetPassword").trim() || undefined;
      const autoFilter = isChecked("#allowAutoFilter");
      const formatCells = isChecked("#allowFormatCells");
      gridApi.value!.exportDataAsExcel({
        protectSheet: {
          password,
          autoFilter,
          formatCells,
        },
      });
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        rowData.value = data;
      };

      fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      rowData,
      onGridReady,
      onBtExport,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[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/vue3/)

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

```ts
<ag-grid-vue
    :columnDefs="columnDefs"
    :excelStyles="excelStyles"
    :defaultExcelExportParams="defaultExcelExportParams"
    /* other grid options ... */>
</ag-grid-vue>

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

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

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  CellStyleModule,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  CsvExportModule,
  ExcelExportParams,
  ExcelStyle,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  NumberFilterModule,
  TextEditorModule,
  TextFilterModule,
  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,
]);

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="container">
      <div class="controls">
        <button v-on:click="onBtExport()" style="margin-bottom: 5px; font-weight: bold">Export to Excel</button>
      </div>
      <div class="grid-wrapper">
        <ag-grid-vue
          style="width: 100%; height: 100%;"
          @grid-ready="onGridReady"
          :excelStyles="excelStyles"
          :columnDefs="columnDefs"
          :defaultColDef="defaultColDef"
          :defaultExcelExportParams="defaultExcelExportParams"
          :rowData="rowData"></ag-grid-vue>
        </div>
      </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IOlympicData> | null>(null);
    const excelStyles = ref<ExcelStyle[]>([
      {
        id: "unlocked",
        interior: {
          color: "#C6EFCE",
          pattern: "Solid",
        },
        protection: {
          protected: false,
          hideFormula: false,
        },
      },
    ]);
    const columnDefs = ref<(ColDef | ColGroupDef)[]>([
      {
        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" },
        ],
      },
    ]);
    const defaultColDef = ref<ColDef>({
      filter: true,
      minWidth: 100,
      flex: 1,
    });
    const defaultExcelExportParams = ref<ExcelExportParams>({
      protectSheet: true,
    });
    const rowData = ref<IOlympicData[]>(null);

    function onBtExport() {
      gridApi.value!.exportDataAsExcel();
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => {
        rowData.value = data;
      };

      fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      excelStyles,
      columnDefs,
      defaultColDef,
      defaultExcelExportParams,
      rowData,
      onGridReady,
      onBtExport,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[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/vue3/)

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