美文网首页
POI读取excel数字列自动带.0的解决办法

POI读取excel数字列自动带.0的解决办法

作者: Java_Explorer | 来源:发表于2019-04-27 16:47 被阅读0次

最近做项目需要用POI读取excel的数据并处理,excel中有一列的整数,读取后值自动带.0

解决办法有两种:

  1. 设置CellType
  2. 使用DataFormatter格式化

使用for循环遍历

for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
    XSSFCell number = xssfRow.getCell(6);
    // 第1种方式
    number.setCellType(CellType.STRING);
    // 第二种方式
    DataFormatter dataFormatter = new DataFormatter();
    String value = dataFormatter.formatCellValue(number);

}

使用foreach循环遍历

for (Cell cell : row) {
    // 第1种方式
    cell.setCellType(CellType.STRING);
    // 第二种方式
    DataFormatter dataFormatter = new DataFormatter();
    String value = dataFormatter.formatCellValue(cell);
}

相关文章

网友评论

      本文标题:POI读取excel数字列自动带.0的解决办法

      本文链接:https://www.haomeiwen.com/subject/esmknqtx.html