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

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日

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法