触发场景描述
easyexcel导出xls正常导出xlsx提示
触发Bug的代码
easyexcel导出xls的代码:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-disposition", "attachment;filename*=utf-8''cc2024.xls");
ExcelWriter writer = EasyExcelFactory.write(resp.getOutputStream()).excelType(ExcelTypeEnum.XLS).build();
WriteSheet sheet1 = new WriteSheet();
sheet1.setSheetName("测试");
sheet1.setSheetNo(0);
WriteTable table = new WriteTable();
table.setTableNo(1);
List<List<String>> headTitles = ListUtils.newArrayList();
headTitles.add(ListUtils.newArrayList("日期"));
table.setHead(headTitles);
writer.write(contentData(), sheet1, table);
writer.finish();
}
private static List<List<Object>> contentData() {
List<List<Object>> contentList = new ArrayList<List<Object>>();
contentList.add(ListUtils.newArrayList("0801"));
contentList.add(ListUtils.newArrayList("0802"));
return contentList;
}
easyexcel导出xlsx的代码:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
resp.setHeader("Content-disposition", "attachment;filename*=utf-8''cc2024.xlsx");
ExcelWriter writer = EasyExcelFactory.write(resp.getOutputStream()).excelType(ExcelTypeEnum.XLSX).build();
WriteSheet sheet1 = new WriteSheet();
sheet1.setSheetName("测试");
sheet1.setSheetNo(0);
WriteTable table = new WriteTable();
table.setTableNo(1);
List<List<String>> headTitles = ListUtils.newArrayList();
headTitles.add(ListUtils.newArrayList("日期"));
table.setHead(headTitles);
writer.write(contentData(), sheet1, table);
writer.finish();
}
private static List<List<Object>> contentData() {
List<List<Object>> contentList = new ArrayList<List<Object>>();
contentList.add(ListUtils.newArrayList("0801"));
contentList.add(ListUtils.newArrayList("0802"));
return contentList;
}
提示的异常或者没有达到的效果
easyexcel导出xls正常打开:
easyexcel导出xlsx报错提示:
Excel 无法打开文件"cc2024(10).xsx”,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配,
1条答案
按热度按时间ygya80vv1#
版本4.0.1无法复现。
如果可以的话,麻烦提供最小的可复现的实例。