通过需求,要对上传的EXCEL文件进行数据读取并入库。由于EXCEL是由前端直传到阿里云,所以只有一个上传后的文件路径。对于先下载在读取在删除的方式觉得十分耗时且无用,所以试图直接根据URL地址来读取流,生成EXCEL对象并读取数据。代码如下:
public static void main(String[] args) throws IOException { URL httpurl=new URL("http://*******.xlsx"); URLConnection urlConnection = httpurl.openConnection(); InputStream is = urlConnection.getInputStream(); XSSFWorkbook wb = new XSSFWorkbook (is); XSSFSheet sheet = wb.getSheetAt(0); int rowNo = sheet.getLastRowNum(); for (int i = 1; i < rowNo; i++) {s XSSFRow row = sheet.getRow(i); XSSFCell cell1 = row.getCell((short) 1); XSSFCell cell2 = row.getCell((short) 2); XSSFCell cell3 = row.getCell((short) 3); String ce1 = cell1 == null?"空":cell1.getStringCellValue()

本文介绍了在通过阿里云上传路径直接读取EXCEL文件时遇到的POI异常问题,包括'POI java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException'和'POI java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlOptions'。解决方案包括检查xmlbeans-2.3.0.jar是否已添加到项目库,以及在调用XSSFCell方法前检查cell是否为null。此外,还提到了HSSFWorkbook和XSSFWorkbook的区别,以及针对大数据导出如何避免OOM问题的方法。
最低0.47元/天 解锁文章
7310

被折叠的 条评论
为什么被折叠?



