ExcelWorksheet Protection

Following example demonstrates how to protect a worksheet.

Note that specifying advanced settings like sheet password or allowing some objects to be editable is supported only for XLSX file format.

Sheet Protection Screenshot
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.

        ExcelFile ef = new ExcelFile();
        ExcelWorksheet ws = ef.addWorksheet("Sheet Protection");

        ws.getCell(0, 2).setValue("Only cells from A1 to A10 are editable.");

        for (int i = 0; i < 10; i++) {
            ExcelCell cell = ws.getCell(i, 0);


        // ProtectionSettings class is supported only for XLSX file format.
        ws.getCell(2, 2).setValue("Inserting columns is allowed (only supported for XLSX file format).");
        WorksheetProtection protectionSettings = ws.getProtectionSettings();

        ws.getCell(3, 2).setValue("Sheet password is 123 (only supported for XLSX file format).");

        ef.save("Sheet Protection.%OutputFileType%");

Check next example or download examples from GitHub.