poi导出电子表格的设置
输出设置:writeResponse
String filename = "电子表格.xls"
response.setContentType("application/octet-stream");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO-8859-1"));//文件名支持中文
OutputStream ouputStream = response.getOutputStream();
workbook.write(ouputStream);
ouputStream.flush();
ouputStream.close();
- 上面代码已经设置了文件名,并且支持中文,但是在用postman测试的时候,文件名永远是response.xsl
解决办法:不用postman测试,改为浏览器,并且用 GET 请求方式,即可解决
使用poi库导出电子表格时,尽管设置了自定义的文件名并支持中文,但在Postman测试时,实际下载的文件名始终显示为'response.xls'而非预期的自定义名称。
521





