原文地址:http://blog.csdn.net/ysughw/article/details/9288307

POI操作Excel時偶爾會出現Cannot get a text value from a numeric cell的異常錯誤。

異常原因:Excel資料Cell有不同的型別,當我們試圖從一個數字型別的Cell讀取出一個字串並寫入資料庫時,就會出現Cannot get a text value from a numeric cell的異常錯誤。

此異常常見於類似如下程式碼中:row.getCell(0).getStringCellValue();

解決辦法:先設定Cell的型別,然後就可以把純數字作為String型別讀進來了:

if(row.getCell(0)!=null){

row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
          stuUser.setPhone(row.getCell(0).getStringCellValue());
     }