poi excel文件名或者内容中文乱码
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文件名或者内容中文乱码的更多相关文章
- 解决gitk显示文件内容中文乱码
解决gitk显示文件内容中文乱码 1.git config 命令 设置git gui的界面编码 git config --global gui.encoding utf-8 2.修改配置文件 在~\e ...
- poi 升级至4.x 的问题总结(POI Excel 单元格内容类型判断并取值)
POI Excel 单元格内容类型判断并取值 以前用 cell.getCachedFormulaResultType() 得到 type 升级到4后获取不到了 换为:cell.getCellType( ...
- jxl解析excel时,处理中文乱码问题
jxl解析excel时,处理中文乱码问题 一般出现较多的问题是,当exce中包含了中文或特殊字符时,在解析时候就会出现乱码现象. 解决方法为: InputStream in = new FileInp ...
- phpstudy 首次安装后打开网站 数据库内容 中文乱码
首次安装完成 phpstudy 后,默认的 my.ini 配置只有数据库文件位置,其他的都没有设置,这时如果想要输出数据库中的中文后,显示到页面上就会变成中文乱码 解决方法: 打开 phpstudy ...
- POI Excel 单元格内容类型判断并取值
个人用到的 String birthdayVal = null; ...
- gridview导excel及解决导出中文乱码的方法
要全部展示数据,所以导出时要先将翻页取消,重新绑定数据:gridview的allowpaging属性设置为false,然后databind()一下 <%@ Page Language=" ...
- Excel导入CSV文件中文乱码
参考: iconv -f UTF8 -t GB18030 a.csv >b.csv 或iconv -f UTF-8 -t GB18030 a.csv >b.csv
- lumisoft邮件内容中文乱码问题
修改MIME_b_Text.cs文件,红色字体为添加的部分,绿色为修改部分 private static Encoding m_pEncoding = Encoding.Default; #regio ...
- restTemplate.postForObject上传文件中文乱码(???.xls)
一.问题描述 项目中, 使用restTemplate上传文件时, 文件名中文乱码, 一串问号, 源文件名为: 测试中文乱码哦哦哦.zip, 通过restTemplate.postForObject调用 ...
随机推荐
- 数据仓库专题(21):Kimball总线矩阵说明-官方版
一.前言 Over the years, I have found that a matrix depiction of the data warehouse plan is a pretty goo ...
- ubuntu更新提示/boot空间不足
1. 查看当前使用的内核版本 uname -a 2.在终端下察看已经安装的旧的内核: ctrl+alt+t——>进入终端——>输入命令: dpkg --get-selections|gre ...
- gitlab ssh clone问题解决
公司搭建的gitlab,通过http协议可以clone: [sisi@pre-srv24 gitlab]$ git clone http://gitlab.test.mycompany.com/dev ...
- Ubuntu 14.10 下编译Hadoop2.4.0
在http://www.aboutyun.com/thread-8130-1-1.html 这里看到到,安装过程遇到了上面说的问题,所以将此文转载过来,以备不时之需,感谢此作者. 问题导读: 1.如果 ...
- webscoket通信初步(一)
只要动手做起来,多投入时间和精力.耐心去研究,以大多人的智商加google,平时遇到的大部分问题我们都是可以自己解决的,大部分的知识我们都是可以掌握的. 我们都知道http协议是单向请求的,无法实现双 ...
- 阿里云ECS专有网络下安装flannel注意事项
参照文章http://www.cnblogs.com/lyzw/p/6016789.html在两台阿里云ECS主机安装与配置flannel,在专有网络下两台主机只能通过公网ip连通,所以flannel ...
- ES6基础一
声明方式 var和let的区别 1,var用来声明全局变量,let用来声明局部变量: 2,var可以提升变量,let声明的变量不在变量提升: const声明常 ...
- 学习笔记之k-nearest neighbors algorithm (k-NN)
k-nearest neighbors algorithm - Wikipedia https://en.wikipedia.org/wiki/K-nearest_neighbors_algorith ...
- 廖雪峰Java5集合-6Stack-1使用Stack
1.栈的定义 栈Stack是一种后进先出(LIFO: Last In First Out)的数据结构,可以看作一端封闭的容器,先进去的元素永远在底部,最后出来. 栈有2个重要的方法: push(E e ...
- re模块小结
一.引子: 文件err.txt中有如下内容: 要求提取出所有的电话号码来. 方法一:文件操作法: f = open('eer.txt','r',encoding='utf-8') l = [] for ...