@@ -37,26 +37,58 @@ public function isValid(Cell $cell): bool
37
37
if (!is_numeric ($ cellValue ) || fmod ((float ) $ cellValue , 1 ) != 0 ) {
38
38
$ returnValue = false ;
39
39
} else {
40
- $ returnValue = $ this ->numericOperator ($ dataValidation , (int ) $ cellValue );
40
+ $ returnValue = $ this ->numericOperator ($ dataValidation , (int ) $ cellValue, $ cell );
41
41
}
42
42
} elseif ($ type === DataValidation::TYPE_DECIMAL || $ type === DataValidation::TYPE_DATE || $ type === DataValidation::TYPE_TIME ) {
43
43
if (!is_numeric ($ cellValue )) {
44
44
$ returnValue = false ;
45
45
} else {
46
- $ returnValue = $ this ->numericOperator ($ dataValidation , (float ) $ cellValue );
46
+ $ returnValue = $ this ->numericOperator ($ dataValidation , (float ) $ cellValue, $ cell );
47
47
}
48
48
} elseif ($ type === DataValidation::TYPE_TEXTLENGTH ) {
49
- $ returnValue = $ this ->numericOperator ($ dataValidation , mb_strlen ($ cell ->getValueString ()));
49
+ $ returnValue = $ this ->numericOperator ($ dataValidation , mb_strlen ($ cell ->getValueString ()), $ cell );
50
50
}
51
51
52
52
return $ returnValue ;
53
53
}
54
54
55
- private function numericOperator (DataValidation $ dataValidation , int |float $ cellValue ): bool
55
+ private function numericOperator (DataValidation $ dataValidation , int |float $ cellValue, Cell $ cell ): bool
56
56
{
57
+ $ calculation = null ;
57
58
$ operator = $ dataValidation ->getOperator ();
58
59
$ 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
+ }
60
92
$ returnValue = false ;
61
93
if ($ operator === DataValidation::OPERATOR_BETWEEN ) {
62
94
$ returnValue = $ cellValue >= $ formula1 && $ cellValue <= $ formula2 ;
0 commit comments