码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-11-20 16:18:58      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:ring   tab   code   date   ble   excel   row   dateutil   npoi   

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

 

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

标签:ring   tab   code   date   ble   excel   row   dateutil   npoi   

原文地址:https://www.cnblogs.com/2515593227blog/p/9989281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!