对浏览器提供数据导出后台

// 输出Excel文件
try {
OutputStream output = response.getOutputStream();
response.reset();
// 设置分区中文名
String filename = "商品价格预警";
// 设置响应的编码
response.setContentType("application/x-download");// 下面三行是关键代码,处理乱码问题
response.setCharacterEncoding("utf-8");
// 设置浏览器响应头对应的Content-disposition
response.setHeader("Content-disposition",
"attachment;filename=" + new String(filename.getBytes("gbk"), "iso8859-1") + ".xls");
workBook.write(output);
output.close();
workBook.close();
} catch (IOException e) {
e.printStackTrace();
}


//poi写法
posted @ 2020-02-13 11:16  Blogs_zcc  阅读(185)  评论(0)    收藏  举报