1.文件名乱码处理

		// excel文件名
String fileName="我报表";
          final SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHH24mmssSSS");
final String formatStr = formatter.format(new Date());
fileName = fileName + formatStr + "." + fileType;
System.out.println(fileName); final HSSFWorkbook wb = createHSSFWorkbook(map);
// try {// for testing,created the file in server in path "/home/ap/user/domins/user"
// final FileOutputStream xlsStream = new FileOutputStream(fileName);
// wb.write(xlsStream);
// xlsStream.flush();
// xlsStream.close();
// } catch (final Exception e) {
// e.printStackTrace();
// } // 响应到客户端
try {
// 解决文件乱码
final String userAgent = request.getHeader("user-agent");
if (userAgent != null && userAgent.indexOf("Firefox") >= 0
|| userAgent.indexOf("Chrome") >= 0 || userAgent.indexOf("Safari") >= 0) {
fileName = new String(fileName.getBytes(), "ISO8859-1");
} else {
fileName = URLEncoder.encode(fileName, "UTF8"); // 其他浏览器
} // setResponseHeader(response, fileName); response.reset();// 清除首部的空白行
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
// response.setHeader("Content-Disposition", "inline;filename=" + fileName);
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.flushBuffer();
final OutputStream os = response.getOutputStream();
// os.write(wb.getBytes());
wb.write(os);
os.flush();
os.close(); } catch (final Exception e) {
e.printStackTrace();
}
}

2.内容乱码:

tempContent = new String(tempContent.getBytes("UTF-8"), "ISO-8859-1");
// System.out.println(tempContent);
tempContent = new String(tempContent.getBytes("ISO-8859-1"), "UTF-8");
cell.setCellValue(tempContent);

3.download.jsp中编码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.userpackage.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request. setCharacterEncoding("UTF-8");
//response.setHeader("Content-Type", "charset=UTF-8");
%>
<%
out.clear();
out = pageContext.pushBody();
ExcelExport.export(request,response);
%>

poi excel文件名或者内容中文乱码的更多相关文章

  1. 解决gitk显示文件内容中文乱码

    解决gitk显示文件内容中文乱码 1.git config 命令 设置git gui的界面编码 git config --global gui.encoding utf-8 2.修改配置文件 在~\e ...

  2. poi 升级至4.x 的问题总结(POI Excel 单元格内容类型判断并取值)

    POI Excel 单元格内容类型判断并取值 以前用 cell.getCachedFormulaResultType() 得到 type 升级到4后获取不到了 换为:cell.getCellType( ...

  3. jxl解析excel时,处理中文乱码问题

    jxl解析excel时,处理中文乱码问题 一般出现较多的问题是,当exce中包含了中文或特殊字符时,在解析时候就会出现乱码现象. 解决方法为: InputStream in = new FileInp ...

  4. phpstudy 首次安装后打开网站 数据库内容 中文乱码

    首次安装完成 phpstudy 后,默认的 my.ini 配置只有数据库文件位置,其他的都没有设置,这时如果想要输出数据库中的中文后,显示到页面上就会变成中文乱码 解决方法: 打开 phpstudy ...

  5. POI Excel 单元格内容类型判断并取值

    个人用到的 String birthdayVal = null;                                                                     ...

  6. gridview导excel及解决导出中文乱码的方法

    要全部展示数据,所以导出时要先将翻页取消,重新绑定数据:gridview的allowpaging属性设置为false,然后databind()一下 <%@ Page Language=" ...

  7. Excel导入CSV文件中文乱码

    参考: iconv -f UTF8 -t GB18030 a.csv >b.csv 或iconv -f UTF-8 -t GB18030 a.csv >b.csv

  8. lumisoft邮件内容中文乱码问题

    修改MIME_b_Text.cs文件,红色字体为添加的部分,绿色为修改部分 private static Encoding m_pEncoding = Encoding.Default; #regio ...

  9. restTemplate.postForObject上传文件中文乱码(???.xls)

    一.问题描述 项目中, 使用restTemplate上传文件时, 文件名中文乱码, 一串问号, 源文件名为: 测试中文乱码哦哦哦.zip, 通过restTemplate.postForObject调用 ...

随机推荐

  1. export,import 的用法

    摘自https://blog.csdn.net/pcaxb/article/details/53670097: 谢谢!

  2. vue中绑定多个class,多个情况使用同一个class时,用js的或 “||”

    class中 当依赖中断的时候是绑定的red,但是这样写绑定不了, 大括号{}里可以下js代码的,下面的orange就可以绑定成功,写成双竖线 形式.

  3. 详细记录sql运行时间(精确到毫秒)

    写程序的人,往往需要分析所写的SQL语句是否已经优化过了,服务器的响应时间有多快,这个时候就需要用到SQL的STATISTICS状态值来查看了. 通过设置STATISTICS我们可以查看执行SQL时的 ...

  4. SET NOCOUNT ON

    每次我们在使用查询分析器调试SQL语句的时候,通常会看到一些信息,提醒我们当前有多少个行受到了影响,这是些什么信息?在我们调用的时候这些信息有用吗?是否可以关闭呢? 答案是这些信息在我们的客户端的应用 ...

  5. pytest.3.Assert

    From: http://www.testclass.net/pytest/assert/ Assert就是断言,每个测试用例都需要断言. 与unittest不同,pytest使用的是python自带 ...

  6. Ubuntu 14.10 下安装伪分布式hbase 0.99.0

    HBase 安装分为:单击模式,伪分布式,完全分布式,在单机模式中,HBase使用本地文件系统而不是HDFS ,所有的服务和zooKeeper都运作在一个JVM中.本文是安装的伪分布式. 安装步骤如下 ...

  7. 珍藏的数据库SQL基础练习题答案

    自己珍藏的数据库SQL基础练习题答案 一,基本表的定义与删除. 题1: 用SQL语句创建如下三张表:学生(Student),课程表(Course),和学生选课表(SC),这三张表的结构如表1-1到表1 ...

  8. HTML背景图片自适应

    由于<body>标签的图片不能够拉伸, 解决办法: 1.图片不够大,又background属性不能拉伸图片: 2.只能用个div,把其z-index值设为负,并使这个div大小为整个bod ...

  9. Spring的LoadTimeWeaver(代码织入)(转)

    https://www.cnblogs.com/wade-luffy/p/6073702.html 在Java 语言中,从织入切面的方式上来看,存在三种织入方式:编译期织入.类加载期织入和运行期织入. ...

  10. CentOS 7安装Oracle 11gR2以及设置自启动(2)

    6.创建表空间和用户授权 (1).连接数据库 $ sqlplus / as sysdba (2).创建数据库表空间 语法: create tablespace 表空间名 datafile ‘物理地址( ...