POI Cannot get a STRING value from a NUMERIC cell The number is not converted into a string cellType Other methods dataFormatter after invalidation

Scenes

After the Excel file is imported, cells of pure numeric type cannot pass

getStringCellValue()

The method directly converts to String

and the original conversion method

cell.setCellType  (CellType.STRING);

does not work and has been deprecated

New convert to String workaround

// index 为当前行的单元格索引值 即第几个单元格 row 为当前行 通过sheet 获取到
Cell nameCell = row.getCell(index);
String cellValue = new DataFormatter().formatCellValue(nameCell);

formatCellValue() After using this method, the value in excel can be read normally and it is String

Guess you like

Origin blog.csdn.net/weixin_44131922/article/details/130706144