POI Cannot get a STRING value from a NUMERIC cell 数字没有转成字符串 cellType 失效后的其他方法dataFormatter

场景

Excel 文件导入后,纯数字类型的单元格不能通过

getStringCellValue()

方法直接转为String

且原有转换方法

cell.setCellType  (CellType.STRING);

不起作用且已经被废弃

新的转为 String 解决方法

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

formatCellValue() 使用该方法后可以正常读取excel 中的数值且为String

猜你喜欢

转载自blog.csdn.net/weixin_44131922/article/details/130706144