I want to open a password protected docx file using Apache POI. Can anyone help me with the complete code please? Am not getting solution with this code
Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF) at org.apache.poi.poifs.storage.HeaderBlock.(HeaderBlock.java:126) at org.apache.poi.poifs.storage.HeaderBlock.(HeaderBlock.java:113) at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.(NPOIFSFileSystem.java:301) at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:413) at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:394)
POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream("D:/abc.docx"));
EncryptionInfo info=new EncryptionInfo(fs);
Decryptor decryptor=Decryptor.getInstance(info);
if(!decryptor.verifyPassword("user"))
{
throw new RuntimeException("document is encrypted");
}
InputStream in=decryptor.getDataStream(fs);
HSSFWorkbook wb=new HSSFWorkbook(in);
File f=new File("D:/abc5.docx");
wb.write(f);