如何从Excel文件单元格使用POI获取数值和string值,我正在获取数值错误,string值很容易获取

目前我正在使用String data= sheet1.getRow(row).getCell(column).getStringCellValue(); 它适用于string值,但显示错误的数值。 所以我不得不在excel中添加像“34567”这样的数字值。 有没有其他的方法来获取数字和string?

当您尝试以stringforms提取数字单元格时,将会出现错误。

在获取数字单元格之前,应该像下面那样将cellType设置为string。

  HSSFCell yourCell = sheet1.getRow(row).getCell(column); yourCell.setCellType(Cell.CELL_TYPE_STRING); String data = yourCell.getStringCellValue(); 

在模板excel中改变列的types为string.then得到的值为string如下sheet1.getRow(row).getCell(column).getStringCellValue()。然后分解为整数或其他。