[英]how to fetch a cell from excel using java whether the cell may contains a string or numeric value?
Here is my code: 这是我的代码:
long tin=0;
tin = (long)row.getCell(10).getNumericCellValue();
tin value of excel may contains string or only numeric value.. if tin value is numeric am able to fetch data.. if tin value is String am getting error. excel的tin值可能包含字符串或仅包含数字值。.如果tin值是数字,则能够获取数据。.如果tin值是String,则报错。
You can check the type of the cell using Cell#getCellTypeEnum() . 您可以使用Cell#getCellTypeEnum()检查单元格的类型。 Possible returned values are: 可能返回的值是:
In other words you should try the following scaffold: 换句话说,您应该尝试以下支架:
tin = row.getCell(10).getCellTypeEnum().equals(CellType.NUMERIC) ?
(long)row.getCell(10).getNumericCellValue() :
Long.parseLong(row.getCell(10).getStringCellValue());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.