Using Apache POI library we can read protected Excel file easily in Java
XLS
AND
Reading protected documents is format-dependent and needs to be implemented per format differently.
POIFSFileSystem fs = new POIFSFileSystem(xlsxFile); EncryptionInfo info = new EncryptionInfo(fs); Decryptor decryptor = Decryptor.getInstance(info); //Verifying the password if (!decryptor.verifyPassword("javacodepoint")) { throw new RuntimeException("Incorrect password"); } InputStream dataStream = decryptor.getDataStream(fs); // Now parse dataStream
In Apache POI, WorkbookFactory is a factory class available for creating the appropriate kind of Workbook (eg. HSSFWorkbook or XSSFWorkbook), by auto-detecting from the supplied input.
For example- WorkbookFactory.create(java.io.File file, java.lang.String password);