java解析Excel(兼容2003及2007):解析2003及以下使用HSSFWorkbook类,
解析2007及以上使用XSSFWorkbook,
如果解析类与excel版本不对应,抛出相应的异常,例如HSSFWorkbook解析2007:
org.apache.poi.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)
XSSF和HSSF虽然在不同的包里,但却都实现了同一接口Workbook,可以先判断excel版本,然后由对应的excel解析类解析,指向同一Workbook变量
1