失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Springmvc使用hutool导出excel中文文件名乱码问题

Springmvc使用hutool导出excel中文文件名乱码问题

时间:2021-02-28 19:50:25

相关推荐

Springmvc使用hutool导出excel中文文件名乱码问题

Springmvc使用hutool导出excel中文文件名乱码问题,原因是tomcat本身没有设置UTF-8,或者字符集问题。

未知原因很多。这些都可以通知对文件名使用URLEncoder.encode来解决。

//response为HttpServletResponse对象response.setContentType("application/vnd.ms-excel;charset=utf-8");//中文编码String fileName = URLEncoder.encode("入住记录", "UTF-8");response.setHeader("Content-Disposition","attachment;filename="+fileName+".xls");ServletOutputStream out=response.getOutputStream();ExcelWriter writer = ExcelUtil.getWriter();// 合并单元格后的标题行,使用默认标题样式writer.merge(9, "入住记录列表");// 一次性写出内容,使用默认样式writer.write(rows);writer.flush(out);writer.close();

如果觉得《Springmvc使用hutool导出excel中文文件名乱码问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。