c#npoi 报错Cannot get a numeric value from a text cell 的解决

一般是因为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);

猜你喜欢

转载自www.cnblogs.com/zuochanzi/p/9083676.html