[英]How to read xlsx file from Java
我正在用Java Eclipse構建一個應用程序。 我想讀取XLS文件。
public Carico leggiOrdineDaFile_Mazzeo(Fornitore f,String file){
try{
FileInputStream inputStream = new FileInputStream(new File(file));
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet firstSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = firstSheet.iterator();
Carico ordine = new Carico();
List<DettOrdini> listaArticoli = new ArrayList<DettOrdini>();
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue());
break;
}
System.out.print(" - ");
}
System.out.println();
}
((BufferedReader) workbook).close();
inputStream.close();
}
但是,如果我嘗試啟動代碼,則會收到以下錯誤消息:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
我已經在我的項目中導入了這個庫:
poi-3.17.jar
poi-excelant-3.17.jar
poi-ooxml-3.17.jar
poi-ooxml-schemas-3.17.jar
poi-scratchpad-3.17.jar
xmlbeans-2.6.0.jar
curveaspi-1.0.4.jar
正如您的錯誤消息所暗示的那樣:您只是缺少import org.apache.commons
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.