思路:1.写入输入流中。

2.将输入流加到ZipOutputStream压缩流中

List<DocumentModel> list = null;

}

//excel表格
HSSFWorkbook wb = documentService.exportBatch1(list);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
wb.write(os);
} catch (IOException e) {
e.printStackTrace();
}
byte[] content = os.toByteArray();

//写入输入流
InputStream is = new ByteArrayInputStream(content);

 

 

// 创建临时文件
File zipFile = File.createTempFile(fileName, ".zip");
FileOutputStream f = new FileOutputStream(zipFile);
CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
// 用于将数据压缩成Zip文件格式
ZipOutputStream zos = new ZipOutputStream(csum);
/**
* 添加excel表格数据
*/
zos.putNextEntry(new ZipEntry("file.xls"));
int bytesRead = 0;
while ((bytesRead = is.read()) != -1) {
zos.write(bytesRead);
}
isclose();
zos.closeEntry();

 

相关文章:

  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-01-14
  • 2022-02-07
  • 2021-11-28
猜你喜欢
  • 2021-11-03
  • 2021-08-07
  • 2022-01-30
  • 2021-07-07
  • 2022-02-26
  • 2022-02-15
相关资源
相似解决方案