private static final int _32MB = 32 * 1024 * 1024;
public static DataIterator getExcelDataIterator(InputStream is,
int sheetIndex) throws Exception {
is = new BufferedInputStream(is);
is.mark(_32MB);
try {
//文件后缀类型判断不如解析时判断Excel类型,文件后缀可以伪造,压缩后后缀名需要另解析
//使用历史版本的逻辑解析2003格式
return new ExcelDataIterator(is, sheetIndex);
} catch (Exception e) {
is.reset();
is.mark(-1);
//2003格式解析失败后尝试用2007的解析方式解析
return new Excel2007DataIterator(is, sheetIndex);
}
}
public static DataIterator getExcelDataIterator(InputStream is,
int sheetIndex) throws Exception {
// 如果不支持标记、重置, 则包装它
if(! is.markSupported()) {
is = new PushbackInputStream(is, 8);
}
if(POIFSFileSystem.hasPOIFSHeader(is)) {
return new ExcelDataIterator(is, sheetIndex);
}
if(POIXMLDocument.hasOOXMLHeader(is)) {
return new Excel2007DataIterator(is, sheetIndex);
}
throw new IllegalArgumentException("Your input was neither an xls , nor an xlsx ");
}