成都的大熊猫 2022-03-28 17:14 采纳率: 0%
浏览 59

poi内容乱码,哪位大知道原因

问题遇到的现象和发生背景

poi 3.17版 excel复杂导出,设置了合并单元格和样式

问题相关代码,请勿粘贴截图

//调用下载
public void downloadExcel(HttpServletResponse response, HSSFWorkbook wb, String fileName) throws IOException {
OutputStream outputStream = null;
try {
outputStream = getOutputStream(response, fileName);
wb.write(outputStream);
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
outputStream.close();
}
}

//输出流
private static OutputStream getOutputStream(HttpServletResponse response, String fileName) {
//创建本地文件
String filePath = fileName + ".xls";
File file = new File(filePath);
try {
if (!file.exists() || file.isDirectory()) {
file.createNewFile();
}
fileName = new String(filePath.getBytes(), "ISO-8859-1");
response.setCharacterEncoding(getSystemFileCharset());
response.addHeader("Content-Disposition", "filename=" + fileName);
return response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

运行结果及报错内容

img

我的解答思路和尝试过的方法

网上能搜到过的 我基本上都试过,无效

我想要达到的结果

各位大,谁能解决poi内容乱码的问题啊,搞了一天愁死了!

  • 写回答

3条回答 默认 最新

  • 关注

    tomcat里面设置一下编码,
    uriencode=utf-8

    <Connector port="8080" maxThreads="150" minSpareThreads="25" 
    maxSpareThreads="75" enableLookups="false" redirectPort="8443" 
    acceptCount="100" debug="99" connectionTimeout="20000" 
    disableUploadTimeout="true" URIEncoding="UTF-8"/>
    
    
    评论 编辑记录

报告相同问题?

问题事件

  • 修改了问题 3月28日
  • 创建了问题 3月28日