@@ 322-355 (lines=34) @@ | ||
319 | // Convert R1C1 style references to A1 style references (but only when not quoted) |
|
320 | $temp = explode('"', $cellDataFormula); |
|
321 | $key = false; |
|
322 | foreach ($temp as &$value) { |
|
323 | // Only count/replace in alternate array entries |
|
324 | if ($key = !$key) { |
|
325 | preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); |
|
326 | // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way |
|
327 | // through the formula from left to right. Reversing means that we work right to left.through |
|
328 | // the formula |
|
329 | $cellReferences = array_reverse($cellReferences); |
|
330 | // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, |
|
331 | // then modify the formula to use that new reference |
|
332 | foreach ($cellReferences as $cellReference) { |
|
333 | $rowReference = $cellReference[2][0]; |
|
334 | // Empty R reference is the current row |
|
335 | if ($rowReference == '') { |
|
336 | $rowReference = $row; |
|
337 | } |
|
338 | // Bracketed R references are relative to the current row |
|
339 | if ($rowReference[0] == '[') { |
|
340 | $rowReference = $row + trim($rowReference, '[]'); |
|
341 | } |
|
342 | $columnReference = $cellReference[4][0]; |
|
343 | // Empty C reference is the current column |
|
344 | if ($columnReference == '') { |
|
345 | $columnReference = $column; |
|
346 | } |
|
347 | // Bracketed C references are relative to the current column |
|
348 | if ($columnReference[0] == '[') { |
|
349 | $columnReference = $column + trim($columnReference, '[]'); |
|
350 | } |
|
351 | $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; |
|
352 | ||
353 | $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); |
|
354 | } |
|
355 | } |
|
356 | } |
|
357 | unset($value); |
|
358 | // Then rebuild the formula string |
@@ 695-729 (lines=35) @@ | ||
692 | // Convert R1C1 style references to A1 style references (but only when not quoted) |
|
693 | $temp = explode('"', $cellDataFormula); |
|
694 | $key = false; |
|
695 | foreach ($temp as &$value) { |
|
696 | // Only replace in alternate array entries (i.e. non-quoted blocks) |
|
697 | if ($key = !$key) { |
|
698 | preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); |
|
699 | // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way |
|
700 | // through the formula from left to right. Reversing means that we work right to left.through |
|
701 | // the formula |
|
702 | $cellReferences = array_reverse($cellReferences); |
|
703 | // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, |
|
704 | // then modify the formula to use that new reference |
|
705 | foreach ($cellReferences as $cellReference) { |
|
706 | $rowReference = $cellReference[2][0]; |
|
707 | // Empty R reference is the current row |
|
708 | if ($rowReference == '') { |
|
709 | $rowReference = $rowID; |
|
710 | } |
|
711 | // Bracketed R references are relative to the current row |
|
712 | if ($rowReference[0] == '[') { |
|
713 | $rowReference = $rowID + trim($rowReference, '[]'); |
|
714 | } |
|
715 | $columnReference = $cellReference[4][0]; |
|
716 | // Empty C reference is the current column |
|
717 | if ($columnReference == '') { |
|
718 | $columnReference = $columnNumber; |
|
719 | } |
|
720 | // Bracketed C references are relative to the current column |
|
721 | if ($columnReference[0] == '[') { |
|
722 | $columnReference = $columnNumber + trim($columnReference, '[]'); |
|
723 | } |
|
724 | $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; |
|
725 | $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); |
|
726 | } |
|
727 | } |
|
728 | } |
|
729 | } |
|
730 | unset($value); |
|
731 | // Then rebuild the formula string |
|
732 | $cellDataFormula = implode('"', $temp); |