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

猜你喜欢

转载自www.cnblogs.com/2515593227blog/p/9989281.html