关闭

页面下载Excel的Zip文件

109人阅读 评论(0) 收藏 举报
分类:

页面下载Excel的Zip文件:


//获取生成好的Excel文件

List<HSSFWorkbook> wbLst = ×××××××;

// 设定responseHeader
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(DateUtils.toDate(new Date(), "yyyyMMddHHmmss") + ".gz", "UTF-8"));


// 把Excel扔到ZIp中
OutputStream out = null;
try {
out = response.getOutputStream();
ZipOutputStream zip = new ZipOutputStream(out);
for (HSSFWorkbook workbook : wbLst) {
ZipEntry entry = new ZipEntry(DateUtils.getCurTime3()+ ".xls");
zip.putNextEntry(entry);
workbook.write(zip);
}

zip.flush();
zip.close();

} catch (IOException e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {


}
}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    文章分类