简体   繁体   中英

C#, Convert Npoi.ICell to Double type

I'm importing numerical data from excel file using NPOI. And as for reading cell, i've got this problem "Cannot implicitly convert convert type NPOI.SS.UserModel.ICell to Double".

    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()
            }

How to convert ICell into specific type like a ToString()?

I can't change type of CellValue into var. because its declared in many other things as double.

Look here for documentation of the ICell. It looks like what you'd want to do is sheet.GetRow(a).GetCell(b).NumericCellValue. You may also want to change toString() to StringCellValue as toString may just return the class name with hash code or something of the sort.

试试这个(未经测试)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM