poi导出excel名称中文乱码(对IE,chrome,Firefox有效)

// 判断浏览器类型,firefox浏览器作特殊处理,不然下载文件名乱码 public static void compatibleFileName(HttpServletRequest request, HttpServletResponse response, String excelname) throws UnsupportedEncodingException { String agent = request.getHeader("USER-AGENT").toLowerCase(); response.setContentType("application/vnd.ms-excel"); String fileName = excelname; 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"); } }
相关文章
相关标签/搜索