1. 程式人生 > >從Excel表中導入數據時日期格式的驗證問題解決

從Excel表中導入數據時日期格式的驗證問題解決

turn parse numeric value bool cat style exc code




#region IsDateTimeType 私有方法判斷導入數據是否是日期格式 /// <summary> /// 私有方法判斷導入數據是否是日期格式 /// </summary> /// <param name="cell"></param> /// <returns></returns> private bool IsDateTimeType(ICell cell) { if (IsDate(cell) == null
) { if (cell.CellType == CellType.NUMERIC && DateUtil.IsCellDateFormatted(cell)) { return true; } else { try { DateTime.Parse(cell.ToString());
return true; } catch { return false; } } } else { return true; } } /// <summary> ///
日期格式判斷 /// </summary> /// <param name="cell">表格列值</param> /// <returns></returns> public DateTime? IsDate(ICell cell) { DateTime? dateTime; try { dateTime = cell.DateCellValue; return dateTime; } catch { return null; } } #endregion IsDateTimeType 私有方法判斷導入數據是否是日期格式

從Excel表中導入數據時日期格式的驗證問題解決