编程语言
首页 > 编程语言> > java-poi-excel-加密

java-poi-excel-加密

作者:互联网

publc class ExcelTest{

      public void test1(){
        //指定输出内容
        File file = new File("E:/20220402/test1.xlsx");
        FileOutputStream out = new FileOutputStream(file);
        // excel内容
        SXSSFWorkbook workbook = new SXSSFWorkbook();
        SXSSFSheet sheet = workbook.createSheet("test");
        SXSSFRow row = sheet.createRow(0);
        SXSSFCell cell = row.createCell(0);
        cell.setCellValue("test1");
        // 加密内容
        EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);
        Encryptor enc = info.getEncryptor();
        enc.confirmPassword("123456");
        // 输出
        POIFSFileSystem fs = new POIFSFileSystem();
        OutputStream os = enc.getDataStream(fs);
        workbook.write(os);
        os.flush();
        os.close();
        fs.writeFilesystem(out);
      }

}

 

标签:test1,enc,java,excel,fs,poi,workbook,new,os
来源: https://www.cnblogs.com/kalajiadisi/p/16091429.html