@@ -850,44 +850,53 @@ private void CheckFormulaCachedValueType(CellType expectedTypeCode, FormulaRecor
850
850
851
851
/// <summary>
852
852
/// Get the value of the cell as a date. For strings we throw an exception.
853
- /// For blank cells we return a null.
853
+ /// For non-Numeric cells including blank cell we return a null.
854
854
/// </summary>
855
855
/// <value>The date cell value.</value>
856
- public DateTime DateCellValue
856
+ public DateTime ? DateCellValue
857
857
{
858
858
get
859
859
{
860
- if ( cellType = = CellType . Blank )
860
+ if ( CellType != CellType . Numeric && CellType ! = CellType . Formula )
861
861
{
862
- return DateTime . MaxValue ;
862
+ return null ;
863
863
}
864
- if ( cellType == CellType . String )
865
- {
866
- throw new InvalidDataException (
867
- "You cannot get a date value from a String based cell" ) ;
868
- }
869
- if ( cellType == CellType . Boolean )
870
- {
871
- throw new InvalidDataException (
872
- "You cannot get a date value from a bool cell" ) ;
873
- }
874
- if ( cellType == CellType . Error )
864
+ double value = this . NumericCellValue ;
865
+ return DateUtil . GetJavaDate ( value , book . IsDate1904 ( ) ) ;
866
+ }
867
+ }
868
+ #if NET6_0_OR_GREATER
869
+ public DateOnly ? DateOnlyCellValue
870
+ {
871
+ get {
872
+ if ( CellType != CellType . Numeric && CellType != CellType . Formula )
875
873
{
876
- throw new InvalidDataException (
877
- "You cannot get a date value from an error cell" ) ;
874
+ return null ;
878
875
}
879
876
double value = this . NumericCellValue ;
880
877
if ( book . IsDate1904 ( ) )
881
878
{
882
- return DateUtil . GetJavaDate ( value , true ) ;
879
+ return DateOnly . FromDateTime ( DateUtil . GetJavaDate ( value , true ) ) ;
883
880
}
884
881
else
885
882
{
886
- return DateUtil . GetJavaDate ( value , false ) ;
883
+ return DateOnly . FromDateTime ( DateUtil . GetJavaDate ( value , false ) ) ;
884
+ }
885
+ }
886
+ }
887
+ public TimeOnly ? TimeOnlyCellValue
888
+ {
889
+ get {
890
+ if ( CellType != CellType . Numeric && CellType != CellType . Formula )
891
+ {
892
+ return null ;
887
893
}
894
+ double value = NumericCellValue ;
895
+ bool date1904 = Sheet . Workbook . IsDate1904 ( ) ;
896
+ return TimeOnly . FromDateTime ( DateUtil . GetJavaDate ( value , date1904 ) ) ;
888
897
}
889
898
}
890
-
899
+ #endif
891
900
/// <summary>
892
901
/// Get the value of the cell as a string - for numeric cells we throw an exception.
893
902
/// For blank cells we return an empty string.
0 commit comments