1

I am using XSSFSheet class of package org.apache.poi.xssf.usermodel and using the below code to password protect the sheet.

XSSFSheet sheet = workbook.createSheet("sheetName");
sheet.protectSheet("password");

Is there any way to unprotect the sheet using the same class(XSSFSheet) ?

Indrapreet
  • 55
  • 8
  • 4
    The javadoc says "_Pass null to remove protection_" - see [here](https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFSheet.html#protectSheet-java.lang.String-). – andrewJames Jun 19 '20 at 15:53
  • @andrewjames Your answer makes sense but what if we are accessing the protected file from another API/Program ? – Indrapreet Jun 22 '20 at 11:25
  • You need the password to access the protected resource. For example, see [here](https://stackoverflow.com/questions/3042694/how-can-i-access-password-protected-excel-workbook-in-java-using-poi-api). Regarding "_another API_" - if you have a specific API in mind (i.e. something other than POI), you can ask a specific question about that (assuming it has not already been asked and answered). – andrewJames Jun 22 '20 at 11:45

1 Answers1

1

Like This

sheet.protectSheet(null);