Excel workbook protection

Workbook protection allows you to protect structure of a workbook against modifications, such as deleting or renaming of sheets.

Note that workbook protection is supported only for XLSX file format.

The following example shows how you can protect a workbook.

Excel workbook protected with GemBox.Spreadsheet
Screenshot of Excel workbook protected with GemBox.Spreadsheet
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = new ExcelFile();
        var worksheet = workbook.Worksheets.Add("Workbook Protection");

        // ProtectionSettings class is supported only for XLSX file format.
        var protectionSettings = workbook.ProtectionSettings;
        protectionSettings.ProtectStructure = true;

        worksheet.Cells[0, 0].Value = "Workbook password is 123 (only supported for XLSX file format).";
        protectionSettings.SetPassword("123");

        workbook.Save("Workbook Protection.xlsx");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook = New ExcelFile
        Dim worksheet = workbook.Worksheets.Add("Workbook Protection")

        ' ProtectionSettings class is supported only for XLSX file format.
        Dim protectionSettings = workbook.ProtectionSettings
        protectionSettings.ProtectStructure = True

        worksheet.Cells(0, 0).Value = "Workbook password is 123 (only supported for XLSX file format)."
        protectionSettings.SetPassword("123")

        workbook.Save("Workbook Protection.xlsx")
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.