Reputation: 1
I need to do the following:
User downloads excel file (which is a template) with some columns read only and other editable;(read only columns were made by protecting entire sheet
//protect entire sheet
sheet.protectSheet("password");
//create style for editable cells
XSSFCellStyle editableStyle = workbook.createCellStyle();
editableStyle.setLocked(false);
//for editable cells apply this style
cell.setCellStyle(editableStyle);
User modifies the template file, filling only editable cells
User upload the template
During uploading the template I need to check if the uploaded file is the one downloaded before, protected with exactly the same "password".
I have the possibility to get the password but it is encoded and I don't know how to decode it.
byte[] password = sheet.getCTWorksheet().getSheetProtection().getPassword();
Can you please help me?
Upvotes: 0
Views: 2182
Reputation: 341
If you want to check if the file is have the same password, then you can use validateSheetPassword
method to check it.
Example:
if (sheet.validateSheetPassword("password"))
print("It same password");
Or you can see the documentation here: https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFSheet.html#validateSheetPassword(java.lang.String)
Upvotes: 1