本文介绍了在Java中加载Excel时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Java中读取一个简单的.xlsx

I'm trying to read a simple .xlsx in java

private void readExcelData(String excel) throws Exception {
    FileInputStream file = new FileInputStream(excel);
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);
}

但是我得到了Exception in thread "AWT-EventQueue-0" java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected

but i get Exception in thread "AWT-EventQueue-0" java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected

我必须添加xmlbeans-xmlpublic-2.3.0.jar,否则它会给我Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException也许与此有关.

I had to add xmlbeans-xmlpublic-2.3.0.jar or it gives me Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlExceptionMaybe it has something to do with that.

有人可以解决吗?

推荐答案

您有一个依赖项问题,请查明正在使用哪个jar.也许需要相冲突的poi jar版本poi-4.1.0.jar,而您却拥有poi-4.0.1.jar.

You have a dependency issue, find out which jar is being used. Perhaps conflicting versions of poi jar, poi-4.1.0.jar is needed and you have poi-4.0.1.jar.

ClassLoader classloader = org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource("org/apache/poi/util/POILogger.class");
String path = res.getPath();
System.out.println("POI came from " + path);

如果使用的是maven,请运行"mvndependency:tree -Dverbose"以显示包含的jar.

If you are using maven, run "mvn dependency:tree -Dverbose" to show included jars.

这篇关于在Java中加载Excel时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:57