I have written code as below to fetch value from Excel.
String CID = s1.getRow(i).getCell(0).getStringCellValue();
but in excel, 1st cell is a numeric value, but in above code I am trying to fetch String cell value. thats why I am getting error as :
Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell
Can anyone please provide a solution for this. how to fetch the numeric value from excel?
getCellType() for any cell gives you the type of the cell.The types are:
It is better to use a switch statement and collect the correct type of cell value. There exists getNumericCellValue() and getStringCellValue() functions but it is safer with types.
Add apostrophe as prefix to that number in cell, automatically it will be converted as text. it had worked for me
Check the cell type first and then get its value.
You should use it =>
I'm not sure, but I think that exists
getNumericalCellValue()
orgetIntegerCellValue()
which returns what you want.