我正在一个模块需要在 xlsx 文件中读/写的应用程序中工作。我已经在我的项目中导入了 Poi.example 3.9 和 xml_beans jar。NoClassDefFoundError
但它仍然在代码中给出错误。这是我的代码:-
try{
FileInputStream file = new FileInputStream(new File("< path of excel file.....xlsx"));
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
//iterate through each row from first sheet
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext()){
Row row = rowIterator.next();
//Fore each row iterate through each column
Iterator<Cell> cellIterator = row.cellIterator();
while(cellIterator.hasNext()){
Cell cell = cellIterator.next();
switch (cell.getCellType()){
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
break;
}
}
System.out.println("");
}
file.close();
FileOutputStream out = new FileOutputStream (new File("< path of excel file.....xlsx"));
wb.write(out);
out.close();
} catch(FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}