C# 导出Excel解决Cannot get a text value from a numeric cell或者Cannot get a numeric value from a text cell

C#开发导出Excel中遇到如下问题中的一种:

Cannot get a text value from a numeric cell

Cannot get a numeric value from a text cell

都是单元格转换问题,一般都出现在单元格获取值的方法处:

string sCellValue = ICell.StringCellValue;
double dNumber = ICell.NumericCellValue;

只需要在上述代码前加上如下代码设置单元格类型即可解决问题:
 

ICell.SetCellType(CellType.String);
ICell.SetCellType(CellType.Numeric);
原创文章 79 获赞 56 访问量 17万+

猜你喜欢

转载自blog.csdn.net/qq_23009105/article/details/89511080