解决导出Excel表的时候,中文文件名出现乱码的问题 |
您所在的位置:网站首页 › 导出是乱码怎么调回文字 › 解决导出Excel表的时候,中文文件名出现乱码的问题 |
我用的是safari浏览器,正确的实现方式如下: String filename = "学生信息"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); //重要点 String fileName = new String(filename.getBytes(), "iso8859-1") + dateFormat.format(new Date().getTime()) + ".xls"; response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename=" + fileName); response.setContentType("application/x-download"); response.flushBuffer(); response.setCharacterEncoding("UTF-8");刚开始的时候我用的是如下方法:这个对我这边不适用 String filename = "学生信息"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); //---------重要点----------- String fileName = new String(filename.getBytes("gb2312"), "iso8859-1") + dateFormat.format(new Date().getTime()) + ".xls"; response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename=" + fileName); response.setContentType("application/x-download"); response.flushBuffer(); response.setCharacterEncoding("UTF-8");原项目中用的是:下载下来发现得到的文件名是对中文文件名转义之后的,也不适用 String filename = "学生信息"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); //---------重要点----------- String fileName = URLEncoder.encode(filename,"utf-8") + dateFormat.format(new Date().getTime()) + ".xls"; response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename=" + fileName); response.setContentType("application/x-download"); response.flushBuffer(); response.setCharacterEncoding("UTF-8");
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |