Protect sheet in Vue Spreadsheet component

3 Jul 202424 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.
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.

<template>
  <ejs-spreadsheet ref="spreadsheet" :created="created">
    <e-sheets>
      <e-sheet name="Budget" :isProtected="true" :protectSettings="{ selectCells: true }">
        <e-ranges>
          <e-range :dataSource="dataSource1"></e-range>
        </e-ranges>
        <e-columns>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
        </e-columns>
      </e-sheet>
      <e-sheet name="Salary">
        <e-ranges>
          <e-range :dataSource="dataSource2"></e-range>
        </e-ranges>
        <e-columns>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
        </e-columns>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
</template>

<script setup>
import { ref } from "vue";
import { SpreadsheetComponent as EjsSpreadsheet, ColumnsDirective as EColumns, ColumnDirective as EColumn, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet } from "@syncfusion/ej2-vue-spreadsheet";
import { salaryData, budgetData } from './data.js';

const spreadsheet = ref(null);
const dataSource1 = budgetData;
const dataSource2 = salaryData;

const created = function () {
  spreadsheet.value.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
  spreadsheet.value.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
  spreadsheet.value.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'Salary!A1:D1');
  spreadsheet.value.protectSheet(1, { selectCells: false });
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
<template>
  <ejs-spreadsheet ref="spreadsheet" :created="created">
    <e-sheets>
      <e-sheet name="Budget" :isProtected="true" :protectSettings="{ selectCells: true }">
        <e-ranges>
          <e-range :dataSource="dataSource1"></e-range>
        </e-ranges>
        <e-columns>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
        </e-columns>
      </e-sheet>
      <e-sheet name="Salary">
        <e-ranges>
          <e-range :dataSource="dataSource2"></e-range>
        </e-ranges>
        <e-columns>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
        </e-columns>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
</template>

<script>
import { SpreadsheetComponent, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { salaryData, budgetData } from './data.js';

export default {
  name: "App",
  components: {
    "ejs-spreadsheet": SpreadsheetComponent,
    "e-sheets": SheetsDirective,
    "e-sheet": SheetDirective,
    "e-ranges": RangesDirective,
    "e-range": RangeDirective,
    "e-columns": ColumnsDirective,
    "e-column": ColumnDirective
  },
  data: () => {
    return {
      dataSource1: budgetData,
      dataSource2: salaryData
    }
  },
  methods: {
    created: function () {
      let spreadsheet = this.$refs.spreadsheet;
      spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
      spreadsheet.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
      spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'Salary!A1:D1');
      spreadsheet.protectSheet(1, { selectCells: false });
    }
  }
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>

Limitations of Protect Sheet

  • Password protection is not supported in Protect sheet feature.

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.

<template>
  <div> <ejs-button id='customBtn' v-on:click.native="btnClick"> Unlock cells</ejs-button>
    <div id="dialog"></div>
    <ejs-spreadsheet ref="spreadsheet" id="spreadsheet" :created="created">
      <e-sheets>
        <e-sheet name="Budget" :isProtected="true" :protectSettings="{ selectCells: true }">
          <e-ranges>
            <e-range :dataSource="dataSource1"></e-range>
          </e-ranges>
          <e-columns>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
          </e-columns>
        </e-sheet>
        <e-sheet name="Salary">
          <e-ranges>
            <e-range :dataSource="dataSource2"></e-range>
          </e-ranges>
          <e-columns>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
          </e-columns>
        </e-sheet>
      </e-sheets>
    </ejs-spreadsheet>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { SpreadsheetComponent as EjsSpreadsheet, ColumnsDirective as EColumns, ColumnDirective as EColumn, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet } from "@syncfusion/ej2-vue-spreadsheet";
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";
import { budgetData, salaryData } from './data.js';
import { Dialog } from '@syncfusion/ej2-popups';

const spreadsheet = ref(null);
let dialogObj;
const dataSource1 = budgetData;
const dataSource2 = salaryData;

const btnClick = function () {
  dialogObj = document.getElementById("dialog").ej2_instances[0];
  dialogObj.show();
}
const lockCells = function () {
  dialogObj = document.getElementById("dialog").ej2_instances[0];
  spreadsheet.value.lockCells('A1:F3', false);
  dialogObj.hide();
}
const dlgButtons = [{ click: lockCells, buttonModel: { isPrimary: 'true', content: 'Learn More' } }];
const created = function () {
  spreadsheet.value.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
  spreadsheet.value.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
  spreadsheet.value.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'Salary!A1:D1');
  // Creating dialog component,
  dialogObj = new Dialog({
    header: 'Spreadsheet',
    target: document.getElementById('spreadsheet'),
    content: '"A1:F3" range of cells has been unlocked.',
    showCloseIcon: true,
    isModel: true,
    visible: false,
    width: '500px',
    buttons: [{
      click: lockCells, buttonModel: { content: 'Ok', isPrimary: true }
    }]
  });
  dialogObj.appendTo('#dialog');
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
<template>
  <div> <ejs-button id='customBtn' v-on:click.native="btnClick"> Unlock cells</ejs-button>
    <div id="dialog"></div>
    <ejs-spreadsheet ref="spreadsheet" id="spreadsheet" :created="created">
      <e-sheets>
        <e-sheet name="Budget" :isProtected="true" :protectSettings="{ selectCells: true }">
          <e-ranges>
            <e-range :dataSource="dataSource1"></e-range>
          </e-ranges>
          <e-columns>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
          </e-columns>
        </e-sheet>
        <e-sheet name="Salary">
          <e-ranges>
            <e-range :dataSource="dataSource2"></e-range>
          </e-ranges>
          <e-columns>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
            <e-column :width=100></e-column>
          </e-columns>
        </e-sheet>
      </e-sheets>
    </ejs-spreadsheet>
  </div>
</template>

<script>
import { SpreadsheetComponent, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
import { budgetData, salaryData } from './data.js';
import { Dialog } from '@syncfusion/ej2-popups';

export default {
  name: "App",
  components: {
    "ejs-button": ButtonComponent,
    "ejs-spreadsheet": SpreadsheetComponent,
    "e-sheets": SheetsDirective,
    "e-sheet": SheetDirective,
    "e-ranges": RangesDirective,
    "e-range": RangeDirective,
    "e-columns": ColumnsDirective,
    "e-column": ColumnDirective
  },
  data: () => {
    return {
      dialogObj: Dialog,
      dataSource1: budgetData,
      dataSource2: salaryData,
      dlgButtons: [{ click: this.lockCells, buttonModel: { isPrimary: 'true', content: 'Learn More' } }],
    }
  },
  methods: {
    created: function () {
      let spreadsheet = this.$refs.spreadsheet;
      spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:D1');
      spreadsheet.cellFormat({ fontWeight: 'bold' }, 'A11:D11');
      spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'Salary!A1:D1');
      // Creating dialog component,
      let dialogObj = new Dialog({
        header: 'Spreadsheet',
        target: document.getElementById('spreadsheet'),
        content: '"A1:F3" range of cells has been unlocked.',
        showCloseIcon: true,
        isModel: true,
        visible: false,
        width: '500px',
        buttons: [{
          click: this.lockCells.bind(this), buttonModel: { content: 'Ok', isPrimary: true }
        }]
      });
      dialogObj.appendTo('#dialog');

    },
    btnClick: function () {
      let dialogObj = document.getElementById("dialog").ej2_instances[0];
      dialogObj.show();
    },
    lockCells: function () {
      let spreadsheet = this.$refs.spreadsheet;
      let dialogObj = document.getElementById("dialog").ej2_instances[0];
      spreadsheet.lockCells('A1:F3', false);
      dialogObj.hide();
    }
  }
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>

Make cells read-only without protecting worksheet

Previously, you could make cells read-only by protecting the entire sheet using the protectSheet method or through the UI option. Meanwhile, to make a specific range of cells editable within a protected sheet, you needed to use the lockCells method, passing the range parameter and setting the isLocked property to false.

Now, you can make an entire row, an entire column, or a specific range of cells read-only using the setRangeReadOnly method without protecting the entire sheet. This method accepts three parameters, as detailed in the following table:

Parameter Description  
readOnly Specifies whether an entire row, an entire column, or a specific range of cells should be set as read-only (true) or editable (false). .
range Specifies the particular range of cells to be set as read-only.  
sheetIndex Specifies the index of the sheet.  

You can make an entire row, an entire column, or a specific range of cells read-only by passing the range as shown in the code snippet below:

// To set read-only for single cell.
spreadsheet.setRangeReadOnly(true, 'A2', 0)
// To set read-only for range of cells.
spreadsheet.setRangeReadOnly(true, 'A2:B5', 0)
// To set read-only for entire row.
spreadsheet.setRangeReadOnly(true, '3:3', 0)
// To set read-only for entire column.
spreadsheet.setRangeReadOnly(true, 'A:A', 0)

You can make the cells read-only in the cell data binding by setting the isReadOnly property to true for the respective rows, columns, and cells. Please refer to the code snippet below to see how to set cells to read-only in the cell data binding:

<ejs-spreadsheet>
    <e-sheets>
        <e-sheet>
        <e-rows>
            <e-row :index="3" :isReadOnly="true"></e-row>
            <e-row :index="4">
                <e-cells>
                    <e-cell :index="4" :isReadOnly="true"></e-cell>
                </e-cells>
            </e-row>  
        </e-rows>
        <e-columns>
            <e-column :isReadOnly="true"></e-column>
        </e-columns>
        </e-sheet>
    </e-sheets>
</ejs-spreadsheet>

The following example demonstrates how to make rows, columns, and cells read-only without protecting the sheet:

<template>
  <div>
  <ejs-button className="e-btn custom-btn" v-on:click.native="readOnlyRow()">Make Row 2 readOnly</ejs-button>
  <ejs-button className="e-btn custom-btn" v-on:click.native="readOnlyCell()">Make E5 cell readOnly</ejs-button>
  <ejs-button className="e-btn custom-btn" v-on:click.native="removeReadOnly()">Remove readOnly</ejs-button>
  <ejs-button className="e-btn custom-btn" v-on:click.native="readOnlyCol()">Make Column A readOnly</ejs-button>
  <ejs-spreadsheet ref="spreadsheet">
    <e-sheets>
      <e-sheet name="Budget">
        <e-ranges>
          <e-range :dataSource="dataSource1"></e-range>
        </e-ranges>
        <e-rows>
          <e-row :index="3" :isReadOnly="true"></e-row>
          <e-row :index="4" >
            <e-cells>
              <e-cell :index="5" :isReadOnly="true"></e-cell>
            </e-cells>
          </e-row>
        </e-rows>
        <e-columns>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100 :isReadOnly="true"></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
        </e-columns>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { SpreadsheetComponent as EjsSpreadsheet, ColumnsDirective as EColumns, ColumnDirective as EColumn, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet, RowsDirective as ERows, RowDirective as ERow, CellsDirective as ECells, CellDirective as ECell } from "@syncfusion/ej2-vue-spreadsheet";
import { budgetData } from './data.js';
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";

const spreadsheet = ref(null);
const dataSource1 = budgetData;
const readOnlyRow= function() {
  spreadsheet.setRangeReadOnly(true, '2:2', spreadsheet.activeSheetIndex);
}
const readOnlyCol = function() {
  spreadsheet.setRangeReadOnly(true, 'A:A', spreadsheet.activeSheetIndex);
}
const readOnlyCell = function() {
  spreadsheet.setRangeReadOnly(true, 'E5:E5', spreadsheet.activeSheetIndex);
}
const removeReadOnly = function() {
  spreadsheet.setRangeReadOnly(false, '2:2', spreadsheet.activeSheetIndex);
  spreadsheet.setRangeReadOnly(false, 'A:A', spreadsheet.activeSheetIndex);
  spreadsheet.setRangeReadOnly(false, 'E5:E5', spreadsheet.activeSheetIndex);
}

</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
<template>
  <div>
  <ejs-button className="e-btn custom-btn" v-on:click.native="readOnlyRow()">Make Row 2 readOnly</ejs-button>
  <ejs-button className="e-btn custom-btn" v-on:click.native="readOnlyCell()">Make E5 cell readOnly</ejs-button>
  <ejs-button className="e-btn custom-btn" v-on:click.native="removeReadOnly()">Remove readOnly</ejs-button>
  <ejs-button className="e-btn custom-btn" v-on:click.native="readOnlyCol()">Make Column A readOnly</ejs-button>
  <ejs-spreadsheet ref="spreadsheet">
    <e-sheets>
      <e-sheet name="Budget">
        <e-ranges>
          <e-range :dataSource="dataSource1"></e-range>
        </e-ranges>
        <e-rows>
          <e-row :index="3" :isReadOnly="true"></e-row>
          <e-row :index="4" >
            <e-cells>
              <e-cell :index="5" :isReadOnly="true"></e-cell>
            </e-cells>
          </e-row>
        </e-rows>
        <e-columns>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100 :isReadOnly="true"></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
          <e-column :width=100></e-column>
        </e-columns>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
  </div>
</template>

<script>
import { SpreadsheetComponent, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { budgetData } from './data.js';
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";

export default {
  name: "App",
  components: {
    "ejs-spreadsheet": SpreadsheetComponent,
    "ejs-button": ButtonComponent,
    "e-sheets": SheetsDirective,
    "e-sheet": SheetDirective,
    "e-ranges": RangesDirective,
    "e-rows": RowsDirective,
    "e-row": RowDirective,
    "e-cells": CellsDirective,
    "e-cell": CellDirective,
    "e-range": RangeDirective,
    "e-columns": ColumnsDirective,
    "e-column": ColumnDirective
  },
  data: () => {
    return {
      dataSource1: budgetData
    }
  },
  methods: {
    readOnlyRow() {
      var spreadsheet = this.$refs.spreadsheet;
      spreadsheet.setRangeReadOnly(true, '2:2', spreadsheet.activeSheetIndex);
    },
    readOnlyCol() {
      var spreadsheet = this.$refs.spreadsheet;
      spreadsheet.setRangeReadOnly(true, 'A:A', spreadsheet.activeSheetIndex);
    },
    readOnlyCell() {
      var spreadsheet = this.$refs.spreadsheet;
      spreadsheet.setRangeReadOnly(true, 'E5:E5', spreadsheet.activeSheetIndex);
    },
    removeReadOnly() {
      var spreadsheet = this.$refs.spreadsheet;
      spreadsheet.setRangeReadOnly(false, '2:2', spreadsheet.activeSheetIndex);
      spreadsheet.setRangeReadOnly(false, 'A:A', spreadsheet.activeSheetIndex);
      spreadsheet.setRangeReadOnly(false, 'E5:E5', spreadsheet.activeSheetIndex);
    }
  }
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>

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.

<template>
  <ejs-spreadsheet ref="spreadsheet" :isProtected="true">
    <e-sheets>
      <e-sheet>
        <e-ranges>
          <e-range :dataSource="dataSource"></e-range>
        </e-ranges>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
</template>

<script setup>
import { SpreadsheetComponent as EjsSpreadsheet, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet } from "@syncfusion/ej2-vue-spreadsheet";
import { defaultData } from './data.js';

const dataSource = defaultData;
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
<template>
  <ejs-spreadsheet ref="spreadsheet" :isProtected="true">
    <e-sheets>
      <e-sheet>
        <e-ranges>
          <e-range :dataSource="dataSource"></e-range>
        </e-ranges>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
</template>

<script>
import { SpreadsheetComponent, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { defaultData } from './data.js';

export default {
  name: "App",
  components: {
    "ejs-spreadsheet": SpreadsheetComponent,
    "e-sheets": SheetsDirective,
    "e-sheet": SheetDirective,
    "e-ranges": RangesDirective,
    "e-range": RangeDirective
  },
  data: () => {
    return {
      dataSource: defaultData
    }
  }
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>

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.

<template>
  <ejs-spreadsheet ref="spreadsheet" password='syncfusion'>
    <e-sheets>
      <e-sheet>
        <e-ranges>
          <e-range :dataSource="dataSource"></e-range>
        </e-ranges>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
</template>

<script setup>
import { SpreadsheetComponent as EjsSpreadsheet, RangesDirective as ERanges, RangeDirective as ERange, SheetsDirective as ESheets, SheetDirective as ESheet } from "@syncfusion/ej2-vue-spreadsheet";
import { defaultData } from './data.js';

const dataSource = defaultData;
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>
<template>
  <ejs-spreadsheet ref="spreadsheet" password='syncfusion'>
    <e-sheets>
      <e-sheet>
        <e-ranges>
          <e-range :dataSource="dataSource"></e-range>
        </e-ranges>
      </e-sheet>
    </e-sheets>
  </ejs-spreadsheet>
</template>

<script>
import { SpreadsheetComponent, RangesDirective, RangeDirective, SheetsDirective, SheetDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { defaultData } from './data.js';

export default {
  name: "App",
  components: {
    "ejs-spreadsheet": SpreadsheetComponent,
    "e-sheets": SheetsDirective,
    "e-sheet": SheetDirective,
    "e-ranges": RangesDirective,
    "e-range": RangeDirective
  },
  data: () => {
    return {
      dataSource: defaultData
    }
  }
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
</style>

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.

Limitations of Protect Workbook

  • Encryption with password is not supported in the Protect workbook feature.

Note

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

See Also