C#,将Npoi.ICell转换为Doubletypes

我使用NPOI从Excel文件导入数值数据。 至于阅读单元格,我有这个问题“不能隐式转换转换typesNPOI.SS.UserModel.ICell为双”。

public class Clas { public double CellValue; public string CellName; } ... public CLAS ClasMaker(int a, int b) { C ClaA; ClaA.CellValue = sheet.GetRow(a).GetCell(b) // here ClaA.CellName = sheet.Getrow(a).GetCell(b-1).ToString() // As for string its okay i used ToString() } 

如何将ICell转换为像ToString()这样的特定types?

我无法将CellValue的types更改为var。 因为它在其他许多事情上宣称是双重的。

在这里寻找ICell的文档。 它看起来像你想要做的是sheet.GetRow(a).GetCell(b).NumericCellValue。 你也可能想把toString()改成StringCellValue,因为toString可能只是用哈希码或类别的东西来返回类名。

试试这个(未经testing)

 ClaA.CellValue = Convert.ToDouble(sheet.GetRow(a).GetCell(b).getStringCellValue());