Java POI 读取 Excel 数字转字符串方法详解
在使用 POI 读取 Excel 文件时,可以使用以下方法将数字读取为字符串:
- 使用 DataFormatter 类将数字转换为字符串
DataFormatter formatter = new DataFormatter();
String cellValue = formatter.formatCellValue(cell);
- 将单元格的格式设置为文本格式
cell.setCellType(CellType.STRING);
String cellValue = cell.getStringCellValue();
注意:在使用第二种方法时,如果单元格中包含非数字字符,则会导致读取错误。因此,建议使用第一种方法。
原文地址: https://www.cveoy.top/t/topic/nDlX 著作权归作者所有。请勿转载和采集!