异常螺纹"主" java.lang.IllegalStateException:不能从数字单元获得的文本值 [英] Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell
问题描述
我已经写了code下面从Excel获取价值。
I have written code as below to fetch value from Excel.
String CID = s1.getRow(i).getCell(0).getStringCellValue();
但在Excel中,第一个单元是一个数值,但在上述code我试图获取字符串单元格的值。这就是为什么我得到错误的:
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
任何人都可以请提供了一个解决方案。如何从Excel中获取数值?
Can anyone please provide a solution for this. how to fetch the numeric value from excel?
推荐答案
getCellType()任何细胞给你是cell.The类型的类型:
getCellType() for any cell gives you the type of the cell.The types are:
Cell.CELL_TYPE_BLANK
Cell.CELL_TYPE_NUMERIC
Cell.CELL_TYPE_STRING
Cell.CELL_TYPE_FORMULA
Cell.CELL_TYPE_BOOLEAN
Cell.CELL_TYPE_ERROR
这是更好地使用switch语句,并收集了正确的型格值。
存在getNumericCellValue()和getStringCellValue()的功能,但它是与类型安全
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.
这篇关于异常螺纹"主" java.lang.IllegalStateException:不能从数字单元获得的文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!