POI excel 加密,解密

解密:
(in Excel 2003)
POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream("yourexcelfile.xls")); Biff8EncryptionKey.setCurrentUserPassword("ABCXYZ"); HSSFWorkbook wb = new HSSFWorkbook(pfs);
(in Excel 2007)
POIFSFileSystem pfs = newPOIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("yourexcelfile.xlsx")); EncryptionInfo encInfo = new EncryptionInfo(pfs); Decryptor decryptor = new Decryptor(encInfo); decryptor.verifyPassword("ABCXYZ"); XSSFWorkbook wb = new XSSFWorkbook(decryptor.getDataStream(pfs));

加密:
// 创 建一个工作薄
POIFSFileSystem poif = new POIFSFileSystem(new FileInputStream(FILE));
//EncryptionInfo info = new EncryptionInfo(poif);
HSSFWorkbook wb = new HSSFWorkbook(poif);
// 设置密 码 保 护 ·
Biff8EncryptionKey.setCurrentUserPassword("test");
wb.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(), "");
wb.unwriteProtectWorkbook();
//wb.writeProtectWorkbook("test", "micky");
//HSSFSheet sheet = wb.getSheetAt(0);
//sheet.protectSheet("test");
// 写入excel文件
fileOut = new FileOutputStream(OUT_FILE);
wb.write(fileOut);
fileOut.close();

上面的方法加密后,有一个只读可以查看。没有找到读加密的方式。
也不知道怎么使用poifs.crypt.EncryptionInfo进行加密????
一直没有找到这样的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值