既然是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());
时间: 2024-11-08 20:05:46