NPOI 读取Excel 表数据 数据里面带日期时的处理方法

将ExcelToDataTable 方法下的 

//if (row.GetCell(j) != null) //同理,没有数据的单元格都默认是null
// dataRow[j] = row.GetCell(j).ToString(); 

替换为

    if (row.GetCell(j) != null)
                            {
                                ICell cell = row.GetCell(j);
                                //Cell为非NUMERIC时,调用IsCellDateFormatted方法会报错,所以先要进行类型判断
                                if (cell.CellType == CellType.Numeric && DateUtil.IsCellDateFormatted(cell))
                                    dataRow[j] = cell.DateCellValue.ToString("yyyy/MM/dd");
                                else
                                {
                                    dataRow[j] = row.GetCell(j).ToString();
                                }
                            }

 

posted @ 2018-11-20 15:35  QDXX  阅读(763)  评论(0编辑  收藏  举报