前言
业务开发中,后端返回的excel文件在前端下载时,中文名称显示下划线
代码如下:
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("content-disposition", "attachment;filename=" + filename);
原因
setHeader里的属性值未设置正确(具体原因还未定位到)
处理
代码逻辑修改成:
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + new String(filename.getBytes(StandardCharsets.UTF_8),"ISO8859-1"));