3 回答

TA贡献1788条经验 获得超4个赞
我推荐以下方式,它不会尝试将 an 转换HSSFCell为Integer/ int:
// get the cell as object (this is NOT a number, instead, it contains one)
HSSFCell numberCell = sheet.getRow(1).getCell(26);
// get the cell value as double (there is no direct integer version)
double cellValue = numberCell.getNumericCellValue();
// cast the value to an int
int number = (int) cellValue;

TA贡献1862条经验 获得超7个赞
从 Excel 中读取Double值而不是将值显示为2.0后,要将其打印为2 ,您可以使用DecimalFormat 类方法,并且可以使用以下解决方案:
HSSFCell number = sheet.getRow(1).getCell(26);
Double result =Double.valueOf(number);
DecimalFormat format = new DecimalFormat();
format.setDecimalSeparatorAlwaysShown(false);
System.out.println(format.format(result));
如果您的用例是打印您可以添加的字符串String.valueOf()格式,您可以使用以下解决方案:
HSSFCell number = sheet.getRow(1).getCell(26);
Double result =Double.valueOf(number);
DecimalFormat format = new DecimalFormat();
format.setDecimalSeparatorAlwaysShown(false);
System.out.println(String.valueOf(format.format(result)));

TA贡献1785条经验 获得超8个赞
你可以试试
int L = Integer.parseInt(getRow(1).getCell(26).getStringCellValue());
添加回答
举报