@@ 316-349 (lines=34) @@ | ||
313 | // Convert R1C1 style references to A1 style references (but only when not quoted) |
|
314 | $temp = explode('"', $cellDataFormula); |
|
315 | $key = false; |
|
316 | foreach ($temp as &$value) { |
|
317 | // Only count/replace in alternate array entries |
|
318 | if ($key = !$key) { |
|
319 | preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); |
|
320 | // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way |
|
321 | // through the formula from left to right. Reversing means that we work right to left.through |
|
322 | // the formula |
|
323 | $cellReferences = array_reverse($cellReferences); |
|
324 | // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, |
|
325 | // then modify the formula to use that new reference |
|
326 | foreach ($cellReferences as $cellReference) { |
|
327 | $rowReference = $cellReference[2][0]; |
|
328 | // Empty R reference is the current row |
|
329 | if ($rowReference == '') { |
|
330 | $rowReference = $row; |
|
331 | } |
|
332 | // Bracketed R references are relative to the current row |
|
333 | if ($rowReference[0] == '[') { |
|
334 | $rowReference = $row + trim($rowReference, '[]'); |
|
335 | } |
|
336 | $columnReference = $cellReference[4][0]; |
|
337 | // Empty C reference is the current column |
|
338 | if ($columnReference == '') { |
|
339 | $columnReference = $column; |
|
340 | } |
|
341 | // Bracketed C references are relative to the current column |
|
342 | if ($columnReference[0] == '[') { |
|
343 | $columnReference = $column + trim($columnReference, '[]'); |
|
344 | } |
|
345 | $A1CellReference = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; |
|
346 | ||
347 | $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); |
|
348 | } |
|
349 | } |
|
350 | } |
|
351 | unset($value); |
|
352 | // Then rebuild the formula string |
@@ 670-704 (lines=35) @@ | ||
667 | // Convert R1C1 style references to A1 style references (but only when not quoted) |
|
668 | $temp = explode('"', $cellDataFormula); |
|
669 | $key = false; |
|
670 | foreach ($temp as &$value) { |
|
671 | // Only replace in alternate array entries (i.e. non-quoted blocks) |
|
672 | if ($key = !$key) { |
|
673 | preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); |
|
674 | // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way |
|
675 | // through the formula from left to right. Reversing means that we work right to left.through |
|
676 | // the formula |
|
677 | $cellReferences = array_reverse($cellReferences); |
|
678 | // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, |
|
679 | // then modify the formula to use that new reference |
|
680 | foreach ($cellReferences as $cellReference) { |
|
681 | $rowReference = $cellReference[2][0]; |
|
682 | // Empty R reference is the current row |
|
683 | if ($rowReference == '') { |
|
684 | $rowReference = $rowID; |
|
685 | } |
|
686 | // Bracketed R references are relative to the current row |
|
687 | if ($rowReference[0] == '[') { |
|
688 | $rowReference = $rowID + trim($rowReference, '[]'); |
|
689 | } |
|
690 | $columnReference = $cellReference[4][0]; |
|
691 | // Empty C reference is the current column |
|
692 | if ($columnReference == '') { |
|
693 | $columnReference = $columnNumber; |
|
694 | } |
|
695 | // Bracketed C references are relative to the current column |
|
696 | if ($columnReference[0] == '[') { |
|
697 | $columnReference = $columnNumber + trim($columnReference, '[]'); |
|
698 | } |
|
699 | $A1CellReference = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; |
|
700 | $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); |
|
701 | } |
|
702 | } |
|
703 | } |
|
704 | } |
|
705 | unset($value); |
|
706 | // Then rebuild the formula string |
|
707 | $cellDataFormula = implode('"', $temp); |