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 for Java
Screenshot of Excel workbook protected with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using the Professional version, put your serial key below.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Workbook Protection");

        // ProtectionSettings class is supported only for XLSX file format.
        WorkbookProtection protectionSettings = workbook.getProtectionSettings();
        protectionSettings.setProtectStructure(true);

        worksheet.getCell(0, 0).setValue("Workbook password is 123 (only supported for XLSX file format).");
        protectionSettings.setPassword("123");

        workbook.save("Workbook Protection.xlsx");
    }
}

See also


Next steps

GemBox.Spreadsheet for Java is a component that enables you to read, write, edit and convert spreadsheet files from your applications using one simple API.

Download Buy