public String readExcel(String columnname,String UserType) {
try {
FileInputStream file = new FileInputStream(path);
@SuppressWarnings("resource")
XSSFWorkbook wr = new XSSFWorkbook(file);
XSSFSheet sh = wr.getSheet(prop.getProperty("env"));
int row = sh.getPhysicalNumberOfRows();
System.out.println(row);
for(int j=0;j<row;j++) {
if((sh.getRow(j).getCell(1).getStringCellValue()).equalsIgnoreCase(UserType)) {
for(int i=0;i<row;i++) {
String s=sh.getRow(0).getCell(i).getStringCellValue();
if(s.equals(columnname)) {
value = sh.getRow(0).getCell(i).getStringCellValue();
}
}
}
}
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return value;
}
public static void main(String args[]) {
Util obj=new Util();
obj.readExcel("Username","Testuser1");
}
我正在使用此代码从 Excel 读取数据,但在线程“main”中出现异常java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected
。
不知道原因,请问有人可以帮我吗?
将其添加到您的 pom.xml 文件中
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>x.x.x</version>
</dependency>
的版本poi-ooxml and poi应该是一样的。
我假设你已经有了poi在你的 pom.xml 文件中
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>x.x.x</version>
</dependency>
希望这可以帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)