场景
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
当导入Excel文件后,纯数字单元格无法通过getStringCellValue()转换为String。已废弃的cell.setCellType(CellType.STRING)方法无效。现在,可以使用新的方法newDataFormatter().formatCellValue(cell)来正确读取并转换数字单元格为String类型。

2778

被折叠的 条评论
为什么被折叠?



