Bootstrap

导出excel中文文件名乱码问题

简单解决方法:

 /**
     * 报表命名兼容浏览器转换
      * @param request request
     * @param fileName 报表名
     * @return
     */
    public static String exportFileName(HttpServletRequest request, String fileName) {
        final String userAgent = request.getHeader("USER-AGENT");
        String exportfilename = fileName;
        try {
            if (org.apache.commons.lang3.StringUtils.contains(userAgent, "MSIE")) {
                //IE浏览器
                exportfilename = URLEncoder.encode(exportfilename, "UTF8");
            } else if (org.apache.commons.lang3.StringUtils.contains(userAgent, "Mozilla")) {
                //google,火狐浏览器
                exportfilename = new String(exportfilename.getBytes(), "ISO8859-1");
            } else {
                exportfilename = URLEncoder.encode(exportfilename, "UTF8");
                //其他浏览器
            }
        } catch (UnsupportedEncodingException e) {
            logger.error("EXCEL报表命名兼容浏览器转换失败");
        }
        return exportfilename;
    }

无效后解决方法:

        String fileName = URLEncoder.encode("名字"+".xlsx","utf-8");
        response.addHeader("Content-Disposition", "attachment;filename="+fileName);
        response.setContentType("application/octet-stream");
;