NPOI 日期类型读取

 ICell cell = row.GetCell(i);
                    if (cell.CellType == CellType.NUMERIC)
                    {
                        //NPOI中数字和日期都是NUMERIC类型的,这里对其进行判断是否是日期类型
                        if (HSSFDateUtil.IsCellDateFormatted(cell))//日期类型
                        {
                            dataRow[i] = cell.DateCellValue;
                        }
                        else//其他数字类型
                        {
                            dataRow[i] = cell.NumericCellValue;
                        }
                    }
                    else if (cell.CellType == CellType.BLANK)//空数据类型
                    {
                        dataRow[i] = "";
                    }
                    else if (cell.CellType == CellType.FORMULA)//公式类型
                    {
                        HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(workbook);
                        dataRow[i] = eva.Evaluate(cell).StringValue;
                    }
                    else //其他类型都按字符串类型来处理
                    {
                        dataRow[i] = cell.StringCellValue;
                    }

猜你喜欢

转载自blog.csdn.net/liangyaomu/article/details/68491024