Bug in shared formulas: non-fixed cells are not updated if the formula has a fixed cell (#2354)

Example: right shift shared formula: IF(A$1=0,0,A1/A$1)
Expected value: IF(B$1=0,0,B1/B$1)
Actual value: IF(B$1=0,0,A1/B$1)

Similar behavior is observed when copying formulas vertically.
This issue occurs because a fixed and a non-fixed cell hit the same element of the $newCellTokens array by index $cellIndex
This commit is contained in:
Zaytcev Ivan 2021-11-04 19:39:58 +04:00 committed by GitHub
parent b1c9f0a1bc
commit 89edc5b267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -717,10 +717,12 @@ class ReferenceHelper
$toString = ($match[2] > '') ? $match[2] . '!' : '';
$toString .= $modified3;
[$column, $row] = Coordinate::coordinateFromString($match[3]);
$columnAdditionalIndex = $column[0] === '$' ? 1 : 0;
$rowAdditionalIndex = $row[0] === '$' ? 1 : 0;
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = Coordinate::columnIndexFromString(trim($column, '$')) + 100000;
$row = (int) trim($row, '$') + 10000000;
$cellIndex = $row . $column;
$cellIndex = $row . $rowAdditionalIndex . $column . $columnAdditionalIndex;
$newCellTokens[$cellIndex] = preg_quote($toString, '/');
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString, '/') . '(?!\d)/i';

View File

@ -1,6 +1,20 @@
<?php
return [
[
'=IF(A$1=0,0,A1/A$1)',
1,
0,
'2021',
'=IF(B$1=0,0,B1/B$1)',
],
[
'=IF($A1=0,0,A1/$A1)',
0,
1,
'2021',
'=IF($A2=0,0,A2/$A2)',
],
[
'=SUM(C3:E5)',
-2,