版权声明
1. 本站文章和资源均来自互联网收集和整理,本站不承担任何责任及版权问题。
2. 相关版权归作者及其公司所有,仅供学习研究用途,请勿用于商业目的。
3. 请于下载后24小时内删除,如果喜欢此资源,请购买正版。
4. 若侵犯您的版权,请发邮件至webmaster@ishare1.cn联系我们,我们确认后将立即删除。
出现的问题:在chrome浏览器中导出的excel文件名没有出现中文乱码的情况,在测试IE浏览器的时候,导出的文件名乱码了。
解决方法:
原来的代码:
try { response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=" + new String((edTemplate.getTemplateName() + "导入模板").getBytes(), "ISO-8859-1") + ".xls"); OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); return ResponseMsgUtil.failure(); }
在new String((edTemplate.getTemplateName() + "导入模板").getBytes(), "ISO-8859-1") 的getBytes()这个方法里加上一个编码
修改后的代码
try { response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=" + new String((edTemplate.getTemplateName() + "导入模板").getBytes("gb2312"), "ISO-8859-1") + ".xls"); OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); return ResponseMsgUtil.failure(); }
更多java知识请关注java基础教程栏目。