poi excel export 乱码

时间:2023-03-09 13:44:09
poi excel export 乱码

1. Question Description:

  ~前端是get方式提交的,参数含有中文“测试”

  ~导出的excel,文件名正常, 而标题乱码

2. Solution:

~断点发现, 参数接收就是乱码,

~String excelTitle = new String(objectgroupname.getBytes("ISO-8859-1"), "utf-8");

~HSSFSheet sheet = book.createSheet(excelTitle);//sheet的名字

~response.reset();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        String filename = objectgroupname + ".xls";
        response.setHeader("Content-Disposition", "attachment;filename="+ filename);
        response.setCharacterEncoding("utf-8");

  ~原来传过来的不作处理,再传回浏览器就不是乱码。