If you do not know what you have, but you know the password, you should use WorkbookFactory.create and pass the password to it, for example
Workbook wb = WorkbookFactory.create(new File("protected.xls"),
"NiceSecurePassword");
WorkbookFactorywill identify the type, then will cause the corresponding decryption and downloading of the book for you. If the file is not protected, the password will be ignored.
.
, .xlsx, , , - :
Workbook wb = null;
try {
wb = new XSSFWorkbook(new File("test.xlsx"));
} catch (EncryptedDocumentException e) {
// Password protected, try to decrypt and load
}
XSSFWorkbook .xlsx, EncryptedDocumentException, , , ,