@@ -465,5 +465,105 @@ public void BaseShouldReturnCorrectResultWithMinValue()
465465 Assert . AreEqual ( "00B4" , result ) ;
466466 }
467467 }
468+
469+ [ TestMethod ]
470+ public void IsFormulaShouldReturnCorrectValueWhenNoFormula ( )
471+ {
472+ using ( var package = new ExcelPackage ( ) )
473+ {
474+ var sheet = package . Workbook . Worksheets . Add ( "sheet1" ) ;
475+ sheet . Cells [ "A1" ] . Value = 400 ;
476+ sheet . Cells [ "A4" ] . Formula = "ISFORMULA(A1)" ;
477+ sheet . Calculate ( ) ;
478+ var result = sheet . Cells [ "A4" ] . Value ;
479+ Assert . IsFalse ( ( bool ) result ) ;
480+ }
481+ }
482+
483+ [ TestMethod ]
484+ public void IsFormulaShouldReturnCorrectValueWhenFormula ( )
485+ {
486+ using ( var package = new ExcelPackage ( ) )
487+ {
488+ var sheet = package . Workbook . Worksheets . Add ( "sheet1" ) ;
489+ sheet . Cells [ "A1" ] . Formula = "1+0" ;
490+ sheet . Cells [ "A4" ] . Formula = "ISFORMULA(A1)" ;
491+ sheet . Calculate ( ) ;
492+ var result = sheet . Cells [ "A4" ] . Value ;
493+ Assert . IsTrue ( ( bool ) result ) ;
494+ }
495+ }
496+
497+ [ TestMethod ]
498+ public void IsFormulaShouldReturnCorrectValueWhenArray ( )
499+ {
500+ using ( var package = new ExcelPackage ( ) )
501+ {
502+ var sheet = package . Workbook . Worksheets . Add ( "sheet1" ) ;
503+ sheet . Cells [ "A1" ] . Formula = "1+0" ;
504+ sheet . Cells [ "A3" ] . Value = 1 ;
505+ sheet . Cells [ "A4" ] . Formula = "ISFORMULA(A1:A3)" ;
506+ sheet . Calculate ( ) ;
507+ var result = sheet . Cells [ "A4" ] . Value ;
508+ Assert . IsTrue ( ( bool ) result ) ;
509+ result = sheet . Cells [ "A5" ] . Value ;
510+ Assert . IsFalse ( ( bool ) result ) ;
511+ }
512+ }
513+
514+ [ TestMethod ]
515+ public void IsFormulaShouldReturnCorrectValueWhenArrayFormula ( )
516+ {
517+ using ( var package = new ExcelPackage ( ) )
518+ {
519+ var sheet = package . Workbook . Worksheets . Add ( "sheet1" ) ;
520+ sheet . Cells [ "A1:A3" ] . Formula = "1+0" ;
521+ sheet . Cells [ "A4" ] . Formula = "ISFORMULA(A1:A3)" ;
522+ sheet . Calculate ( ) ;
523+ var result = sheet . Cells [ "A4" ] . Value ;
524+ Assert . IsTrue ( ( bool ) result ) ;
525+ result = sheet . Cells [ "A5" ] . Value ;
526+ Assert . IsTrue ( ( bool ) result ) ;
527+ }
528+ }
529+
530+ [ TestMethod ]
531+ public void IsFormulaShouldReturnCorrectValueWhenLegacyArrayFormula ( )
532+ {
533+ using ( var package = new ExcelPackage ( ) )
534+ {
535+ var sheet = package . Workbook . Worksheets . Add ( "sheet1" ) ;
536+ sheet . Cells [ "A1" ] . Value = 1 ;
537+ sheet . Cells [ "A2" ] . Value = 3 ;
538+ sheet . Cells [ "A3" ] . Value = 5 ;
539+ sheet . Cells [ "B1" ] . Value = 2 ;
540+ sheet . Cells [ "B2" ] . Value = 4 ;
541+ sheet . Cells [ "B3" ] . Value = 6 ;
542+ sheet . Cells [ "E6" ] . CreateArrayFormula ( "A1:B3+1" ) ;
543+ sheet . Cells [ "E11" ] . Formula = "ISFORMULA(E6)" ;
544+ sheet . Cells [ "F11" ] . Formula = "ISFORMULA(F6)" ;
545+ sheet . Calculate ( ) ;
546+ var result = sheet . Cells [ "E11" ] . Value ;
547+ Assert . IsTrue ( ( bool ) result ) ;
548+ result = sheet . Cells [ "F11" ] . Value ;
549+ Assert . IsFalse ( ( bool ) result ) ;
550+ }
551+ }
552+
553+ [ TestMethod ]
554+ public void IsFormulaShouldReturnCorrectValueWhenDynamicArrayFormula ( )
555+ {
556+ using ( var package = new ExcelPackage ( ) )
557+ {
558+ var sheet = package . Workbook . Worksheets . Add ( "sheet1" ) ;
559+ sheet . Cells [ "A1" ] . Formula = "RANDARRAY(3,1)" ;
560+ sheet . Cells [ "A4" ] . Formula = "ISFORMULA(A1:A3)" ;
561+ sheet . Calculate ( ) ;
562+ var result = sheet . Cells [ "A4" ] . Value ;
563+ Assert . IsTrue ( ( bool ) result ) ;
564+ result = sheet . Cells [ "A5" ] . Value ;
565+ Assert . IsFalse ( ( bool ) result ) ;
566+ }
567+ }
468568 }
469569}
0 commit comments