在一次导入的开发过程中,使用了
Workbook wb = null; if(fileName.endsWith(XLS)){ //2003 workbook = new HSSFWorkbook(fileUpload.getInputStream()); }else if(fileName.endsWith(XLSX)){ //2007 workbook = new XSSFWorkbook(fileUpload.getInputStream()); }else{ throw new Exception("文件不是Excel文件"); }
来判断导入的文件类型。但是由于Excel中的内容和编码的原因,导致在导入的过程中报错:
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)
后来各种百度,发现可以使用以下方法替代上述判断方式:
Workbook wb = WorkbookFactory.create(is);