java如何直接返回excel到客户端
既然是web项目首先你得拿到响应才能向外部写出,你得拿到响应对象response,
1.添加如下两行代码
response.setContentType("application/vnd..ms-excel");
response.setHeader("content-Disposition","attachment;filename="+URLEncoder.encode(“abc.xlsx”,"utf-8"));
2.修改你的写出方式:
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
hssfWorkbook.write(response.getOutputStream());