我相信我有我需要的所有jar文件,我仍然收到這個說由導致錯誤:的Java讀取Excel文件
java.lang.reflect.InvocationTargetException
原諒我,我在閱讀錯誤信息方面仍然不太好。該錯誤提示的問題是與線"Workbook book = new XSSFWorkbook(stream);"
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class excelReader {
public static void main(String[] args) throws IOException{
String spreadSheetFilePath = "C:\\Users\\userExample\\Documents\\forJava.xlsx";
FileInputStream stream = new FileInputStream(new File(spreadSheetFilePath));
Workbook book = new XSSFWorkbook(stream);
Sheet sheetOne = book.getSheetAt(0);
Iterator<Row> iterator = sheetOne.iterator();
while(iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIter = nextRow.cellIterator();
while(cellIter.hasNext()) {
Cell cell = cellIter.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();
}
book.close();
stream.close();
}
}
錯誤我得到
Exception in thread "main" org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:65)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:601)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:174)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:279)
at excelReader.main(excelReader.java:18)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:62)
... 4 more
Caused by: java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setLoadEntityBytesLimit(I)Lorg/apache/xmlbeans/XmlOptions;
at org.apache.poi.POIXMLTypeLoader.<clinit>(POIXMLTypeLoader.java:50)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:85)
... 10 more
Jar文件在我的圖書館項目:
commons- codec-1.10.jar
commons-logging1-2.jar
的dom4j-1.1.jar
的JUnit 4.1.2.17.jar
POI-3.14-20160307.jar
POI-excelant-3.14-20160307.jar
POI-OOXML-架構 - 3.14-20160307.jar
POI暫存器-3.14-20160307.jar
的xmlbeans-2.3.0.jar
...張力升高:-)什麼** **是實際跟蹤/錯誤信息?也許這裏有人擅長閱讀它...... – Dilettant
問題區域更適合追溯。允許更多字符和行保持行 – Dilettant
歡迎您,不需要找藉口。應該有一個編輯鏈接接近你的問題。評論還有其他問題,您只能在創建後不超過五分鐘才能對其進行編輯。 – Dilettant