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"); } }
相關文章
相關標籤/搜索