码迷,mamicode.com
首页 > 编程语言 > 详细

解决Java POI 导出Excel时文件名中文乱码,兼容浏览器

时间:2017-09-22 22:44:04      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:poi   new   cte   ref   contains   use   tchar   bsp   pos   

 

   String agent = request.getHeader("USER-AGENT").toLowerCase();
   response.setContentType("application/vnd.ms-excel");
   String fileName = "文件名";
   String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
   if (agent.contains("firefox")) {
           response.setCharacterEncoding("utf-8");
           response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1") + ".xls" );
  } else {
          response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
   }

解决Java POI 导出Excel时文件名中文乱码,兼容浏览器

标签:poi   new   cte   ref   contains   use   tchar   bsp   pos   

原文地址:http://www.cnblogs.com/wangjiagang/p/7577055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!