Wednesday, 19 February 2020 06:28

Java unprotect the Excel file

Written by  support iceblue
Rate this item
(0 votes)

We have already demonstrated how to protect the Excel file in Java; this article will show you how to unprotect the Excel workbook or a single worksheet in Java applications.

Unprotect the Excel workbook:

import com.spire.xls.*;

public class UnprotectExcel {
    public static void main(String[] args) {

        //Create a workbook 
        Workbook workbook = new Workbook();

        //Use the password to open the sample document
        workbook.setOpenPassword("E-iceblue");
        workbook.loadFromFile("ProtectWorkbook.xlsx");

        //Unprotect the whole workbook
        workbook.unProtect();

        //Save the document to file
        workbook.saveToFile("UnprotectWb.xlsx");
        workbook.dispose();
    }
}

Unprotect a single Excel worksheet:

import com.spire.xls.*;

public class UnprotectExcel {
    public static void main(String[] args) {

        //Create a workbook and load a sample file with protected worksheet
        Workbook workbook = new Workbook();
        workbook.loadFromFile("ProtectWS.xlsx");
        
        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Unprotect the first worksheet
        sheet.unprotect("iceblue");

        //Save the document to file
        workbook.saveToFile("Unprotectworksheet.xlsx");
        workbook.dispose();
    }
}

Additional Info

  • tutorial_title: