The error tells you that the cell if type NUMERIC
, you may use the approriate method getNumericCellValue()
String date = "" + sheets.getRow(choosenRow).getCell(3).getNumericCellValue();
If you don't know the type before, and need to read some values, you may implment a switch
on the type (getCellType()
) and from the result of this enum use the right method
Specifically for the numeric type, you can check for date element :
public String getContent(Cell c){
switch(c.getCellType()){
case: NONE : throw new IllegalArgumentException("NONE");
case: BLANK : return "";
case: BOOLEAN : return ""+c.getBooleanCellValue();
case: ERROR : return ""+c.getErrorCellValue()
case: FORMULA : return c.getCellFormula()
case: NUMERIC : return HSSFDateUtil.isCellDateFormatted(c)) ?
c.getDateCellValue()) : ""+c.getNumericCellValue();
case: STRING : return c.getStringCellValue()
}
Ref to How to read Excel cell having Date with Apache POI?