简体   繁体   English

密码保护 XSSFWorkBook Apache POI

[英]Password Protect XSSFWorkBook Apache POI

I need to password protect XSSFWorkBook.我需要密码保护 XSSFWorkBook。 For HSSF, I am able to do it easily but the same implementation is not working for XSSFWorkBook.对于 HSSF,我可以轻松完成,但相同的实现不适用于 XSSFWorkBook。

I am using Apache POI 3.6 and 3.9 both.我同时使用 Apache POI 3.6 和 3.9。 I mean I tried using both 3.6 and 3.9.我的意思是我尝试使用 3.6 和 3.9。

I guess I need to use POIFSFileSystem but can anyone guide me for the same.我想我需要使用 POIFSFileSystem 但任何人都可以指导我。

Password Protect is supported by latest version of poi.最新版本的 poi 支持密码保护。

Please see http://poi.apache.org/encryption.html请参阅http://poi.apache.org/encryption.html

Have tried the suggested method and it is working fine.已经尝试了建议的方法,它工作正常。

Base on Apache POI - Encryption support doc.基于Apache POI - 加密支持文档。

It is depend on file system, that mean MS-Office 2003 or MS-Office 2007 , etc..它取决于文件系统,即MS-Office 2003MS-Office 2007等。

The following program work in MS-Office 2007 .以下程序在MS-Office 2007 Please, check the documentation请检查文档

POIFSFileSystem filesystem = --> get your filesystem
EncryptionInfo encInfo = new EncryptionInfo(filesystem); 
Decryptor decryptor = new Decryptor(encInfo); 
decryptor.verifyPassword("your-password"); 
XSSFWorkbook wb = new XSSFWorkbook(decryptor.getDataStream(filesystem))

Using Apache POI we can read the password protected files, but their is no option to create the password protected files.使用 Apache POI,我们可以读取受密码保护的文件,但无法创建受密码保护的文件。

So try some other commercial library like Aspose .所以尝试一些其他的商业库,比如Aspose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM