This project is read-only.

NPOI change cellType if it is numeric

Oct 16, 2015 at 10:56 PM
Edited Oct 16, 2015 at 10:57 PM
Hi,

I am Using NPOI to read excel data, i have a numeric datatype which i need to change it to text.

Can some please guide to convert numeric to text.

Someone please advice...Thanks
for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
            {
                sheet.GetRow(i);
                IRow row = sheet.GetRow(i);

                
                DataRow dataRow = dt.NewRow();
                if (row == null)
                {
                    break;
                }
                for (int j = row.FirstCellNum; j < cellCount; j++)
                {
                 
                    if (row.GetCell(j) != null)
                    {
                        if (row.GetCell(j).CellType == CellType.Numeric)  
                        {
                            dataRow[j] = row.GetCell(j).NumericCellValue;  // here i need to change it to string
                        }
                        else {
                            dataRow[j] = row.GetCell(j);
                        }
                    }
                }

                dt.Rows.Add(dataRow);
            }
            return dt;
Coordinator
Dec 1, 2015 at 1:11 AM
set the CellType of the cell to String