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 ...
- PyQt5显示一个空白的窗口
效果如下图: """ In this example, we create a simple window in PyQt5. """ # ...
- 【剑指offer】规则二维数组查找
在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 思路: ...
- 符合seo的html标签优化
原文地址:http://www.rainleaves.com/html/1032.html seo(Search Engine Optimiztion)搜索引擎优化的英文缩写.通过总结搜索引擎的 ...
- mysql 意向锁的作用
直接copy知乎上的内容 https://www.zhihu.com/question/51513268 作者:尹发条地精链接:https://www.zhihu.com/question/51513 ...
- PHP中常用的数组函数总结
整理了一份PHP开发中数组操作大全,包含有数组操作的基本函数,数组的分段和填充,数组与栈,数组与列队,回调函数,排序,计算,其他的数组函数等. 一,数组操作的基本函数 数组的键名和值 array_va ...
- 项目中自己一直用到的baseAdapter的类
import java.util.LinkedList; import java.util.List; import android.content.Context; import android.v ...
- BrowserSync前端同步测试工具
安装教程
- [UE4]更新UI的三种方式
一.函数绑定 二.属性绑定 只会列出匹配的数据类型. 三.事件驱动更新 啦啦啦啦啦 结论:函数和属性绑定的原理都是每帧都去调用绑定的函数/属性,效率比较低下,一般不推荐使用.事件驱动更新的效率最好,性 ...
- 转]GSM模块信号强度CSQ与RSSI的对应关系
使用GSM或者3G模块时,都会接触到信号强度CSQ.通过指令AT+CSQ,模块返回当前的信号质量,例如: AT+CSQ +CSQ: 28,0 其中28就是信号强度CSQ,但它不是真实的CSQ,他应该叫 ...