开发者社区> 问答> 正文

关于POI将2007excel加密(不能只读)?报错

java开发,需要实现一个功能:将excel进行加密。然后碰到问题。

    public static void main(String[] args) throws IOException, InvalidFormatException, GeneralSecurityException {
        POIFSFileSystem fs = new POIFSFileSystem();
        EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
 
        Encryptor enc = info.getEncryptor();
        enc.confirmPassword("12346");
 
        OPCPackage opc = OPCPackage.open(new File("D:/file/20161031/excel.xlsx"), PackageAccess.READ_WRITE);
        OutputStream os = enc.getDataStream(fs);
        opc.save(os);
        opc.close();
 
        FileOutputStream fos = new FileOutputStream("D:/file/20161031/excel.xlsx");
        fs.writeFilesystem(fos);
        fos.close();     
             
        System.out.println("File created!!");
    }

这个是我写的方法。

报错:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.poifs.crypt.EncryptionInfo.<init>(Lorg/apache/poi/poifs/crypt/EncryptionMode;)V
at com.hengtiansoft.xinyunlian.apply.service.Test.main(Test.java:56)

展开
收起
爱吃鱼的程序员 2020-06-08 20:59:23 731 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    你看看是否有加: 

    poi-ooxml,

    poi-ooxml-schemas

    这两个包。不过能正常加密,但是2007excel版版的打不开03版本是没问题的,不知道楼主有没有遇到。

    2020-06-08 20:59:39
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
大批量处理excel文件到ODPS中方案 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载