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());
添加回答
舉報