Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# and NPOI cant read number and string value

Tags:

c#

npoi

I've read a file with NPOI and in one column I have some number values and some char values. I need to check if this Cell contains a char value (like "stop"), and if so then I don't want to read this. This is what I've tried:

if (sheet.GetRow(row) != null and sheet.GetRow(row).GetCell(2).Substr(0,4) != "stop")
{
    Console.Write(sheet.GetRow(row).GetCell(1));
}

However I can't read char and number values using this code.

like image 763
Никита Седавных Avatar asked Jan 18 '26 17:01

Никита Седавных


1 Answers

its bit tricky. See the below approach to read the value. Convert your read value into string object like this sheet.GetRow(row).GetCell(1).ToString();

 XSSFRow row = (XSSFRow)sheet.GetRow(i);
     for (int j = row.FirstCellNum; j < cellCount; j++)
     {
            if (null != row.GetCell(j) && !string.IsNullOrEmpty(row.GetCell(j).ToString()) && !string.IsNullOrWhiteSpace(row.GetCell(j).ToString()))
             {
                Console.Write(row.GetCell(j).ToString());
             }
     }
like image 87
kumar chandraketu Avatar answered Jan 21 '26 07:01

kumar chandraketu