NMN
NMN

Reputation: 35

How can we read default cell format from Excel in Apache POI?

public java.text.Format getDefaultFormat(Cell cell).

I am reading values from an Excel cell and storing it in a database.

The code below is not working, it's giving a type mismatch error.

userdata.setTaskid((int)(row.getCell(0).getNumericCellValue()));
System.out.println(userdata.getTaskid());

Upvotes: 2

Views: 1166

Answers (1)

Ankush G
Ankush G

Reputation: 1081

Following code will give you the cell format and then based on that return integer format you can decide the way to get cell value, e.g. either using getNumericCelValue or getBooleanCelValue etc.

int cellType = row.getCell(0).getCellType();
  • Blank Value = 3
  • Boolean Value = 4
  • Error Value = 5
  • Formula Value = 2
  • Numeric Value = 0
  • String value = 1

Upvotes: 1

Related Questions