嘗試讀取 Excel 文件時出現(xiàn)以下錯誤:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook at Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 2 more我使用以下代碼讀取擴(kuò)展名為 .xls 的 Excel 文件。我曾嘗試通過導(dǎo)入其他 poi jar 來尋找答案,但沒有幫助,我已經(jīng)檢查了網(wǎng)絡(luò)搜索,但再次沒有幫助。public Object[][] getExcelData(String excelLocation, String sheetName) { try { Object dataSets[][] = null; FileInputStream file = new FileInputStream(new File(excelLocation));HSSFWorkbook workbook = new HSSFWorkbook(excelLocation);HSSFSheet sheet = workbook.getSheet(sheetName);int totalRowNum = sheet.getLastRowNum();int totalColumnNum = sheet.getRow(0).getLastCellNum();dataSets = new Object[totalRowNum][totalColumnNum];Iterator<Row> rowIterator = sheet.iterator(); int i = 0;while (rowIterator.hasNext()) { i++;HSSFRow row = (HSSFRow) rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); int j = 0; while (cellIterator.hasNext()) { j++; HSSFCell cell = (HSSFCell) cellIterator.next(); switch (cell.getCellTypeEnum()) { case STRING: dataSets[i][j] = cell.getStringCellValue(); break; case NUMERIC: dataSets[i][j] = cell.getNumericCellValue(); break;
添加回答
舉報(bào)
0/150
提交
取消