POI导出Excel时候总是出现中文名乱码问题

时间:2021-07-20 09:22:16
<span style="font-size:18px;">//设置输出流
OutputStream out = response.getOutputStream();
response.reset();
String fileName = rptName+"_"+date;// 文件名
response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("gbk"),"iso8859-1")+".xlsx");
response.setContentType("application/x-download; charset=UTF-8");</span>

使用实例代码如上:

分析如下代码——将String字符串以gbk编码字节转换为另外一种编码格式的字符串

<span style="font-size:18px;">new String(fileName.getBytes("gbk"),"iso8859-1")+".xlsx"</span>