Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配

解决办法:

    将后缀名称xlsx 改为 xls就可以了

部分代码:
    

//最好设置xls格式,否则会导致wps能打开,微软的excel打不开
		String fileName = "xx表.xls";
		response.setContentType("application/octet-stream"); // 响应内容格
		response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
		wb.write(response.getOutputStream());
		wb.close();

  

猜你喜欢

转载自www.cnblogs.com/irobotzz/p/12283663.html