解決Java POI 匯出Excel時檔名中文亂碼,相容瀏覽器

做你的貓發表於2019-01-25
 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");
   }

 

相關文章