NOPI读取Excel2003、Excel2007或更高级的兼容性问题

出错提示:NPOI.POIFS.FileSystem.OfficeXmlFileException: 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)

原因:这是因为NPOI读取2003时使用的是HSSFWorkbook,更高版本读取需要使用XSSFWorkbook

解决方式:

将代码中HSSFWorkbook修改为XSSFWorkbook,最好是导入文件时选择版本,这样处理更好

IWorkbook workbook = new XSSFWorkbook(file);

posted @ 2020-04-29 14:32  榕树下的回忆  阅读(1590)  评论(0编辑  收藏  举报