Lire fichier xlsx à l'aide de POIFSFileSystem

J'ai besoin d'ôter la protection d'une protégé fichier xlsx.e.g Book1.xlsx
Ci-dessous le code fonctionne très bien pour la première fois, Lit Book1.xlsx, de les décrypter et de nouveau écrire sur le même nom de fichier.

public static void unprotectXLSXSheet(String fileName, String password) {
        try{

            POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fileName));
            EncryptionInfo info = new EncryptionInfo(fs);
            Decryptor d = Decryptor.getInstance(info);
            d.verifyPassword(password);
            InputStream is = d.getDataStream(fs);
            System.out.println(is.available());
            XSSFWorkbook wb = new XSSFWorkbook(OPCPackage.open(is));
            FileOutputStream fileOut;
            fileOut = new FileOutputStream(fileName);
            wb.write(fileOut);
             fileOut.flush();
            fileOut.close();
            }catch(FileNotFoundException ex){
                ex.printStackTrace();
            }catch(IOException ex){
                ex.printStackTrace();

Mais quand même code tente d'accéder à la fonction nouvellement créée non protégés Book1.xlsx(ou n'importe quelle autre non protégés fichier xlsx), il échoue et montrant

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.<init>(HeaderBlock.java:131)
    at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
    at com.wolseley.Excel.TestMainDummy.unprotectXLSXSheet(TestMainDummy.java:113)
    at com.wolseley.Excel.TestMainDummy.main(TestMainDummy.java:52)

j'ai besoin d'aide dans la lecture de fichier xlsx et aussi le déverrouiller à l'aide de mot de passe, comme l'a fait ci-dessus.

OriginalL'auteur JavaTweets | 2014-11-04