数字自动更改为字符串

时间:2012-07-26 12:48:50

标签: apache apache-poi

我正在尝试通过apache poi阅读Excel文件。在一列中我有数据“9780547692289”。在迭代所有列之后,在输出中,数字显示为“9.780547692289E12”。我的意思是数字自动更改为字符串(因为它有'E')。我必须保持这个数字(原样)。我该怎么办..?

3 个答案:

答案 0 :(得分:0)

这可能只是一个显示设置。 “E”仅用于显示数字的科学记数法。

答案 1 :(得分:0)

//从excel获取值时,您可以使用此方法

private String getCellValue(Cell cell) {
    if (cell == null) {
        return null;
    }
    if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
        return cell.getStringCellValue();
    } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
        return cell.getNumericCellValue() + "";
    } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
        return cell.getBooleanCellValue() + "";
    }else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){
        return cell.getStringCellValue();
    }else if(cell.getCellType() == Cell.CELL_TYPE_ERROR){
        return cell.getErrorCellValue() + "";
    } 
    else {
        return null;
    }
}

答案 2 :(得分:0)

这对我有用

if(cell.getCellType()== Cell.CELL_TYPE_NUMERIC || cell.getCellType()== Cell.CELL_TYPE_FORMULA)

{

int i =(int)cell.getNumericCellValue();

String cellText = String.valueOf(i);

}

相关问题