java windows导出excel在office中打开报内容错误,需要修复,linux上下载的excel打不开,解决方法==》设置输出流的长度
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.setHeader("Content-Disposition","attachment;filename*=" + URLEncoder.encode(fileName,"UTF-8") + ".xlsx" );
Workbook workbook = new XSSFWorkbook();
// 读数据
workbook = ExcelExportUtil.exportExcel(params,map);
workbook.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// 设置输出流长度
response.setHeader("Content-Length",String.valueOf(bais.available()));
workbook.write(respose.getOutputStream());
workbook.close();