@@ -37,26 +37,58 @@ public function isValid(Cell $cell): bool
3737 if (!is_numeric ($ cellValue ) || fmod ((float ) $ cellValue , 1 ) != 0 ) {
3838 $ returnValue = false ;
3939 } else {
40- $ returnValue = $ this ->numericOperator ($ dataValidation , (int ) $ cellValue );
40+ $ returnValue = $ this ->numericOperator ($ dataValidation , (int ) $ cellValue, $ cell );
4141 }
4242 } elseif ($ type === DataValidation::TYPE_DECIMAL || $ type === DataValidation::TYPE_DATE || $ type === DataValidation::TYPE_TIME ) {
4343 if (!is_numeric ($ cellValue )) {
4444 $ returnValue = false ;
4545 } else {
46- $ returnValue = $ this ->numericOperator ($ dataValidation , (float ) $ cellValue );
46+ $ returnValue = $ this ->numericOperator ($ dataValidation , (float ) $ cellValue, $ cell );
4747 }
4848 } elseif ($ type === DataValidation::TYPE_TEXTLENGTH ) {
49- $ returnValue = $ this ->numericOperator ($ dataValidation , mb_strlen ($ cell ->getValueString ()));
49+ $ returnValue = $ this ->numericOperator ($ dataValidation , mb_strlen ($ cell ->getValueString ()), $ cell );
5050 }
5151
5252 return $ returnValue ;
5353 }
5454
55- private function numericOperator (DataValidation $ dataValidation , int |float $ cellValue ): bool
55+ private function numericOperator (DataValidation $ dataValidation , int |float $ cellValue, Cell $ cell ): bool
5656 {
57+ $ calculation = null ;
5758 $ operator = $ dataValidation ->getOperator ();
5859 $ formula1 = $ dataValidation ->getFormula1 ();
59- $ formula2 = $ dataValidation ->getFormula2 ();
60+ if (!is_numeric ($ formula1 )) {
61+ $ calculation = Calculation::getInstance ($ cell ->getWorksheet ()->getParent ());
62+
63+ try {
64+ $ result = $ calculation
65+ ->calculateFormula ("= $ formula1 " , $ cell ->getCoordinate (), $ cell );
66+ while (is_array ($ result )) {
67+ $ result = array_pop ($ result );
68+ }
69+ $ formula1 = $ result ;
70+ } catch (Exception ) {
71+ // do nothing
72+ }
73+ }
74+ $ formula2 = 0 ;
75+ if ($ operator === DataValidation::OPERATOR_BETWEEN || $ operator === DataValidation::OPERATOR_NOTBETWEEN ) {
76+ $ formula2 = $ dataValidation ->getFormula2 ();
77+ if (!is_numeric ($ formula2 )) {
78+ $ calculation ??= Calculation::getInstance ($ cell ->getWorksheet ()->getParent ());
79+
80+ try {
81+ $ result = $ calculation
82+ ->calculateFormula ("= $ formula2 " , $ cell ->getCoordinate (), $ cell );
83+ while (is_array ($ result )) {
84+ $ result = array_pop ($ result );
85+ }
86+ $ formula2 = $ result ;
87+ } catch (Exception ) {
88+ // do nothing
89+ }
90+ }
91+ }
6092 $ returnValue = false ;
6193 if ($ operator === DataValidation::OPERATOR_BETWEEN ) {
6294 $ returnValue = $ cellValue >= $ formula1 && $ cellValue <= $ formula2 ;
0 commit comments