17 foreach ($definedNames as $definedName) {
18 $this->definedNames[] = $definedName->getName();
22 public function convertFormula(
string $formula,
string $worksheetName =
''): string
27 if (substr($formula, 0, 1) !==
'=') {
28 $formula =
'=' . $formula;
31 return 'of:' . $formula;
36 $splitCount = preg_match_all(
43 $lengths = array_map(
'strlen', array_column($splitRanges[0], 0));
44 $offsets = array_column($splitRanges[0], 1);
45 $values = array_column($splitRanges[0], 0);
47 while ($splitCount > 0) {
49 $length = $lengths[$splitCount];
50 $offset = $offsets[$splitCount];
53 if (in_array($value, $this->definedNames,
true)) {
54 $formula = substr($formula, 0, $offset) .
'$$' . $value . substr($formula, $offset + $length);
63 $splitCount = preg_match_all(
70 $lengths = array_map(
'strlen', array_column($splitRanges[0], 0));
71 $offsets = array_column($splitRanges[0], 1);
73 $worksheets = $splitRanges[2];
75 $rows = $splitRanges[7];
80 $formula = str_replace(
',',
';', $formula);
81 while ($splitCount > 0) {
83 $length = $lengths[$splitCount];
84 $offset = $offsets[$splitCount];
85 $worksheet = $worksheets[$splitCount][0];
90 if (empty($worksheet)) {
91 if (($offset === 0) || ($formula[$offset - 1] !==
':')) {
93 $worksheet = $worksheetName;
96 $worksheet = str_replace(
"''",
"'", trim($worksheet,
"'"));
98 if (!empty($worksheet)) {
99 $newRange =
"['" . str_replace(
"'",
"''", $worksheet) .
"'";
100 } elseif (substr($formula, $offset - 1, 1) !==
':') {
105 if (!empty($column)) {
106 $newRange .= $column;
112 $newRange .= substr($formula, $offset + $length, 1) !==
':' ?
']' :
'';
114 $formula = substr($formula, 0, $offset) . $newRange . substr($formula, $offset + $length);
const CALCULATION_REGEXP_CELLREF_RELATIVE
const CALCULATION_REGEXP_DEFINEDNAME