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");
}
I am using this code to read data from Excel, but getting an exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected
.
Not sure about the reason, can anyone help me with this, please?
Add this in your pom.xml file
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>x.x.x</version>
</dependency>
The version of poi-ooxml and poi should be the same.
I am assuming that you already have poi in your pom.xml file
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>x.x.x</version>
</dependency>
Hope this helps
I got this error when the versions of poi
and poi-ooxml
did not match. This caused the error:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
The error went away after aligning the versions of these libraries:
<properties>
<poi.version>4.1.2</poi.version>
</properties>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With