public static Workbook create(InputStream in) throws IOException,InvalidFormatException {//HSSFWorkbook针对xls,XSSFWorkbook针对xlsx 读取 if (!in.markSupported()) {//先判断是否支持当前的输入流 in = new PushbackInputStream(in, 8);//更改当前的输入流在缓冲区的大小为8字节 } if (POIFSFileSystem.hasPOIFSHeader(in)) { return new HSSFWorkbook(in);//xls文件 } if (POIXMLDocument.hasOOXMLHeader(in)) { return new XSSFWorkbook(OPCPackage.open(in));//xlsx 同意实用WorkBook进行接收 } throw new IllegalArgumentException("你的excel版本目前poi解析不了");//其它操作,这里抛出异常 }
jar:
commons-beanutils-1.8.3.jarcommons-collections4-4.1.jardom4j-1.6.1.jarpoi-3.9-20121203.jarpoi-examples-3.9-20121203.jarpoi-excelant-3.9-20121203.jarpoi-ooxml-3.9-20121203.jarpoi-ooxml-schemas-3.9-20121203.jarpoi-scratchpad-3.9-20121203.jarstax-api-1.0.1.jarxmlbeans-2.3.0.jar
转:http://blog.csdn.net/llwan/article/details/8890190