2012-11-10 119 views

回答

1

Apache POI支持读取加密的XLSX和DOCX文件。请参阅在Apache POI documentation

你的代码应该是这样的:

EncryptionInfo info = new EncryptionInfo(filesystem); 
    Decryptor d = Decryptor.getInstance(info); 

    try { 
     if (!d.verifyPassword(password)) { 
      throw new RuntimeException("Unable to process: document is encrypted"); 
     } 

     InputStream dataStream = d.getDataStream(filesystem); 
     HSSFWorkbook wb = new HSSFWorkbook(dataStream); 
     // parse dataStream 

    } catch (GeneralSecurityException ex) { 
     throw new RuntimeException("Unable to process encrypted document", ex); 
    } 
+0

文件系统? POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream(“example.xls”)); –

+0

是的,文件系统意味着POIFSFileSystem。 http://poi.apache.org/apidocs/org/apache/poi/poifs/filesystem/POIFSFileSystem.html – Chandana