我正在尝试通过 apache poi 读取 Excel 文件。在列中,我有数据“9780547692289”。迭代所有列后,在输出中,数字显示为“9.780547692289E12”。我的意思是数字自动更改为字符串(因为它有'E')。我必须将其保留为仅数字(原样)。我应该怎么办..?
问问题
109 次
3 回答
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;
}
}
于 2012-07-27T10:38:51.873 回答
0
这可能只是一个显示设置。“E”只是用于显示数字的科学计数法。
于 2012-07-26T12:50:45.500 回答
0
这对我有用
if (cell.getCellType()==Cell.CELL_TYPE_NUMERIC || cell.getCellType()==Cell.CELL_TYPE_FORMULA)
{
int i = (int)cell.getNumericCellValue();
字符串 cellText = String.valueOf(i);
}
于 2014-06-04T06:50:06.677 回答