2012-07-26 65 views
0

我想通過apache poi讀取Excel文件。在一列中,我有數據「9780547692289」。迭代所有列後,輸出中的數字顯示爲「9.780547692289E12」。我的意思是數字自動更改爲字符串(因爲它有'E')。我必須保持這個數字(現實)。我該怎麼辦..?號碼自動更改爲字符串

+0

你設置細胞上的CellFormat?如果是這樣,您是否將CellFormat設置爲具有合適的格式字符串?如果不是,爲什麼不呢? ;-) – Gagravarr 2012-07-26 20:15:36

回答

0

它可能只是一個顯示設置。 「E」僅用於顯示數字的科學記數法。

0

//同時從Excel中獲取值u可以使用這種方法

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; 
    } 
} 
0

這爲我工作

如果(cell.getCellType()== Cell.CELL_TYPE_NUMERIC || cell.getCellType() == Cell.CELL_TYPE_FORMULA)

{

INT I =(int)的cell.getNumericCellValue();

String cellText = String.valueOf(i);

}