嗨,我在加载Excel(.xlsx)时遇到问题。
当我尝试加载“巨大”文件(118 MB)时,程序向我抛出此错误:
org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException
但是,如果我尝试使用较小的文件(18 KB),就没有问题。
我已经尝试过使用以下代码:
public ExcelFile(String path){
filePath = path;
try {
OPCPackage pkg = OPCPackage.open(new File(filePath));
workbook = new XSSFWorkbook(pkg);
sheet = workbook.getSheetAt(0);
} catch (Exception e) {
System.out.println("Error en carga o lectura de archivo" + e);
}
}
及其他:
public ExcelFile(String path){
filePath = path;
try {
FileInputStream file = new FileInputStream(new File(filePath));
workbook = new XSSFWorkbook(file);
sheet = workbook.getSheetAt(0);
} catch (Exception e) {
System.out.println("Error en carga o lectura de archivo" + e);
}
}
我希望有人能帮助我。 谢谢
这是完整的堆栈跟踪
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Fail loading file org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at dashboarddesktop.ExcelFile.countRows(ExcelFile.java:55)
at dashboarddesktop.mediator.actionPerformed(mediator.java:70)
at java.awt.Button.processActionEvent(Button.java:409)
at java.awt.Button.processEvent(Button.java:377)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)