我正在尝试从Excel工作表中检索数据,这是代码:
public static void main(String[] args) throws Exception {
File f = new File("C:\\Users\\Alex\\Documents\\Victoria.xlsx");
Workbook wb = WorkbookFactory.create(f);
Sheet s = wb.getSheetAt(0);
Row r =s.getRow(0);
Cell c=r.getCell(0);
s.getLastRowNum();
int rowcount = s.getLastRowNum();
System.out.println("rows are"+rowcount);
System.out.println(c.getStringCellValue());
}
当我运行它时,这是我得到的错误消息:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
## Heading ## org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/C:/Users /Alex/Downloads/selenium-java-3.6.0/poi-3.17/poi-ooxml-3.17.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:266)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:226)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:205)
at CreateSingle_ValueRet.main(CreateSingle_ValueRet.java:13)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.collections4.ListValuedMap
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
我正在使用Eclipse Oxigen。
答案 0 :(得分:0)
您在类路径中遗漏commons-colletions4
。添加它,异常就会消失。