java poi 匯出excel加密
java poi 匯出excel加密
匯出excel加密,要先把excel匯出到伺服器,獲取檔案路徑,加密,下載
maven引入新版本poi jar包
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16-beta2</version>
</dependency>
程式碼
//匯出加密
public static void encryptExportExcel(List<Map> list,String path,String[] title,String[] colum) throws IOException, InvalidFormatException, GeneralSecurityException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
try {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet");
Row row = sheet.createRow(0);
for (int i = 0; i < title.length; i++) {
sheet.setColumnWidth(i,5000);
Cell cell = row.createCell(i);
cell.setCellValue(title[i]);
}
for (int i = 1; i < list.size(); i++) {
Row rowI = sheet.createRow(i);
for (int j = 0; j < colum.length; j++) {
Cell cell = rowI.createCell(j);
cell.setCellValue(list.get(i).get(colum[j])==null?"":list.get(i).get(colum[j]).toString());
//sheet1.createRow(i).createCell(j).setCellValue(list.get(i).get(colum[j])==null?"":list.get(i).get(colum[j]).toString());
}
}
FileOutputStream fileOut = new FileOutputStream(path);
wb.write(fileOut);
fileOut.close();
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = info.getEncryptor();
enc.confirmPassword("123456");
OPCPackage opc = OPCPackage.open(new File(path), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();
FileOutputStream fos = new FileOutputStream(path);
fs.writeFilesystem(fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
相關文章
- poi 匯出Excel java程式碼ExcelJava
- Java之POI操作Excel表-匯入匯出JavaExcel
- poi的excel匯出Excel
- springboot poi匯出excel表格Spring BootExcel
- Java POI匯入Excel檔案JavaExcel
- Java之POI操作,封裝ExcelUtil實現Excel匯入匯出Java封裝Excel
- POI匯出excel檔案加水印Excel
- POI的使用及匯出excel報表Excel
- java實現Excel定製匯出(基於POI的工具類)JavaExcel
- Java匯出ExcelJavaExcel
- 不想用POI?幾行程式碼完成Excel匯出匯入行程Excel
- POI匯入Excel中文API文件ExcelAPI
- java匯出Excel定義匯出模板JavaExcel
- SpringBoot實現Excel匯入匯出,好用到爆,POI可以扔掉了!Spring BootExcel
- JAVA使用poi匯出Excel,合併單元格,設定自動列寬JavaExcel
- 解決Java POI 匯出Excel時檔名中文亂碼,相容瀏覽器JavaExcel瀏覽器
- java使用poi生成excelJavaExcel
- java匯出Excel檔案JavaExcel
- Springboot操作Poi進行Excel匯入Spring BootExcel
- poi 匯出 例項
- Java操作Excel:POI和EasyExcelJavaExcel
- Java架構-Apache POI ExcelJava架構ApacheExcel
- 關於java中Excel的匯入匯出JavaExcel
- 一文搞定POI,再也不怕excel匯入匯出了Excel
- java使使用者EasyExcel匯入匯出excelJavaExcel
- 匯出excelExcel
- Excel匯入匯出-(poi)簡單封裝兩個類,拿來就可以用Excel封裝
- vue excel匯入匯出VueExcel
- PHP 匯出 ExcelPHPExcel
- PHP匯出EXCELPHPExcel
- Vue匯出ExcelVueExcel
- java 匯出到EXCELJavaExcel
- Java用策略模式優雅地匯出ExcelJava模式Excel
- Java使用jxl.jar匯出Excel例項JavaJARExcel
- Excel模板匯出之動態匯出Excel
- Angular Excel 匯入與匯出AngularExcel
- Excel匯入匯出神器(Java)ExcelJava
- vue 前端匯出 excelVue前端Excel
- Excel匯出實列Excel