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调用 ...
随机推荐
- Python中的self和init
From: https://www.crifan.com/summary_the_meaning_of_self_and___init___in_python_and_why_need_them/ 背 ...
- LeetCode——7. Reverse Integer
一.题目链接:https://leetcode.com/problems/reverse-integer/ 二.题目大意: 给定一个整数,要求反转该整数之后再返回:如果归返回的整数超过了int型整数的 ...
- mac nginx 安装教程
eeking a satisfactory solution to create a local web server for programming in macOS with PHP and My ...
- [转][C#]手写 Socket 服务端
private void OpenSocket(int port) { Task.Factory.StartNew(() => { server = new Socket(AddressFami ...
- C语言强化——文件
文件操作 fopen与fclose fread与fwrite fseek fputs与fgets fscanf与fprintf fopen与fclose #include<stdio.h> ...
- IP地址基础
第一台计算机的名字 1946年2月14日,世界上第一台电脑ENIAC在美国宾夕法尼亚大学诞生,名叫ENIAC(爱尼阿克). 第一个网络的名字: arpanet 计算机网络定义: 物理位置不同.功能 ...
- Jmeter(八)HTTPCookie管理器
Cookie绝对是日常工作以及技术中一个绕不过去的‘角色’,正常各种各样的业务需要Cookie的存在.Jmeter中也有支持发送Cookie的组件,但是,仅是后话:在此还是有必要先记一记Cookie到 ...
- php安装imagemagick扩展 常见问题与解决方案(win平台)
1.写在前面 1-1.ImageMagick介绍 ImageMagick是一套功能强大.稳定而且开源的工具集和开发包,可以用来读.写和处理超过89种基本格式的图片文件,包括流行的TIFF.JPEG.G ...
- IBM MQ 中 amqsput : command not found的解决办法
MQ操作队列的命令有如下三条:命令功能1.amqsput 将消息放入队列中, 程序把之后的每一行标准输入作为一条独立的消息,读到 EOF 或空行时退出.注意,UNIX 上的 EOF 为 Ctrl+ ...
- crm SDK 设置用户的上级
/// <summary> /// 设置用户的上级 /// </summary> /// <param name="service">服务< ...