Java使用POI导出Excel .xlsx提示文件格式或文件扩展名有误

转自:https://www.cnblogs.com/songyaru/p/12894357.html

使用POI导出Excel时报错:

1.前端如果用xlsx格式接收表格  后台用XSSFWorkbook workbook = new XSSFWorkbook();创建工作薄

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
 response.addHeader("Content-Disposition", "attachment;filename=fileName" + ".xlsx");

2.前端如果用xls格式接收表格  后台 用HSSFWorkbook workbook = new HSSFWorkbook();创建工作薄

response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment;filename=fileName"+".xls");

(0)

相关推荐