The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals

报错问题

平时在用excelpoi导出的时候会出现以下报错:

The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)

 这是因为:系统无法确定.xls和.xlsx哪种格式,在现在的版本中,大部分都是使用.xlsx,但是后来发现系统找不到该格式,直接把文件名的后缀改成了.xls。

问题解决:

关键问题的原因还是excel版本的问题

(1)判断文件后缀名是xls,还是xlsx;

HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls;

XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx。

(2)如果是xls,使用HSSFWorkbook;如果是xlsx,使用XSSFWorkbook。

猜你喜欢

转载自blog.csdn.net/weixin_64854388/article/details/131739012