1. 程式人生 > >c#npoi 報錯Cannot get a numeric value from a text cell 的解決

c#npoi 報錯Cannot get a numeric value from a text cell 的解決

異常 str etc long rim 否則 ring npoi col

一般是因為cell裏邊的值為數字導致,有時變成文本格式還是解決不了這個問題.  
下邊的代碼是c# 改變設置cell類型的方法 是用這個參數 CellType.String

Row.GetCell((int)customer_level_index).SetCellType(CellType.String);
detail.customer_level = Row.GetCell((int)customer_level_index).StringCellValue;


這個下邊是網上的

POI 實際上setCellValue的時候根據傳入參數的類型會自動設置celltype,所以
long vll = Long.valueOf(vls.trim()); //sheet.getRow(i).getCell(j).setCellType(Cell.CELL_TYPE_NUMERIC); 要mark掉,否則有異常 sheet.getRow(i).getCell(j).setCellValue(vll);

c#npoi 報錯Cannot get a numeric value from a text cell 的解決