Bugfix: Work item 20397 - Serious bug in absolute cell reference used in shared formula

Would also have affected insert/delete column/row
This commit is contained in:
Mark Baker 2013-11-07 23:14:39 +00:00
parent f9f37f566a
commit 94a1a69373
3 changed files with 19 additions and 20 deletions

View File

@ -262,36 +262,34 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
private function _castToFormula($c,$r,&$cellDataType,&$value,&$calculatedValue,&$sharedFormulas,$castBaseType) { private function _castToFormula($c,$r,&$cellDataType,&$value,&$calculatedValue,&$sharedFormulas,$castBaseType) {
// echo 'Formula<br />'; // echo 'Formula',PHP_EOL;
// echo '$c->f is '.$c->f.'<br />'; // echo '$c->f is '.$c->f.PHP_EOL;
$cellDataType = 'f'; $cellDataType = 'f';
$value = "={$c->f}"; $value = "={$c->f}";
$calculatedValue = self::$castBaseType($c); $calculatedValue = self::$castBaseType($c);
// Shared formula? // Shared formula?
if (isset($c->f['t']) && strtolower((string)$c->f['t']) == 'shared') { if (isset($c->f['t']) && strtolower((string)$c->f['t']) == 'shared') {
// echo 'SHARED FORMULA<br />'; // echo 'SHARED FORMULA'.PHP_EOL;
$instance = (string)$c->f['si']; $instance = (string)$c->f['si'];
// echo 'Instance ID = '.$instance.'<br />'; // echo 'Instance ID = '.$instance.PHP_EOL;
// //
// echo 'Shared Formula Array:<pre>'; // echo 'Shared Formula Array:'.PHP_EOL;
// print_r($sharedFormulas); // print_r($sharedFormulas);
// echo '</pre>';
if (!isset($sharedFormulas[(string)$c->f['si']])) { if (!isset($sharedFormulas[(string)$c->f['si']])) {
// echo 'SETTING NEW SHARED FORMULA<br />'; // echo 'SETTING NEW SHARED FORMULA'.PHP_EOL;
// echo 'Master is '.$r.'<br />'; // echo 'Master is '.$r.PHP_EOL;
// echo 'Formula is '.$value.'<br />'; // echo 'Formula is '.$value.PHP_EOL;
$sharedFormulas[$instance] = array( 'master' => $r, $sharedFormulas[$instance] = array( 'master' => $r,
'formula' => $value 'formula' => $value
); );
// echo 'New Shared Formula Array:<pre>'; // echo 'New Shared Formula Array:'.PHP_EOL;
// print_r($sharedFormulas); // print_r($sharedFormulas);
// echo '</pre>';
} else { } else {
// echo 'GETTING SHARED FORMULA<br />'; // echo 'GETTING SHARED FORMULA'.PHP_EOL;
// echo 'Master is '.$sharedFormulas[$instance]['master'].'<br />'; // echo 'Master is '.$sharedFormulas[$instance]['master'].PHP_EOL;
// echo 'Formula is '.$sharedFormulas[$instance]['formula'].'<br />'; // echo 'Formula is '.$sharedFormulas[$instance]['formula'].PHP_EOL;
$master = PHPExcel_Cell::coordinateFromString($sharedFormulas[$instance]['master']); $master = PHPExcel_Cell::coordinateFromString($sharedFormulas[$instance]['master']);
$current = PHPExcel_Cell::coordinateFromString($r); $current = PHPExcel_Cell::coordinateFromString($r);
@ -304,7 +302,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
$difference[0], $difference[0],
$difference[1] $difference[1]
); );
// echo 'Adjusted Formula is '.$value.'<br />'; // echo 'Adjusted Formula is '.$value.PHP_EOL;
} }
} }
} }

View File

@ -702,7 +702,7 @@ class PHPExcel_ReferenceHelper
$cellIndex = $column.$row; $cellIndex = $column.$row;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString);
$cellTokens[$cellIndex] = '/(?<![A-Z])'.preg_quote($fromString).'(?![A-Z])/i'; $cellTokens[$cellIndex] = '/(?<![A-Z\$\!])'.preg_quote($fromString).'(?![A-Z])/i';
++$adjustCount; ++$adjustCount;
} }
} }
@ -728,7 +728,7 @@ class PHPExcel_ReferenceHelper
$cellIndex = $column.$row; $cellIndex = $column.$row;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString);
$cellTokens[$cellIndex] = '/(?<![A-Z])'.preg_quote($fromString).'(?!\d)/i'; $cellTokens[$cellIndex] = '/(?<![A-Z]\$\!)'.preg_quote($fromString).'(?!\d)/i';
++$adjustCount; ++$adjustCount;
} }
} }
@ -740,8 +740,8 @@ class PHPExcel_ReferenceHelper
foreach($matches as $match) { foreach($matches as $match) {
$fromString = ($match[2] > '') ? $match[2].'!' : ''; $fromString = ($match[2] > '') ? $match[2].'!' : '';
$fromString .= $match[3]; $fromString .= $match[3];
$modified3 = $this->updateCellReference($match[3],$pBefore,$pNumCols,$pNumRows);
$modified3 = $this->updateCellReference($match[3],$pBefore,$pNumCols,$pNumRows);
if ($match[3] !== $modified3) { if ($match[3] !== $modified3) {
if (($match[2] == '') || (trim($match[2],"'") == $sheetName)) { if (($match[2] == '') || (trim($match[2],"'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2].'!' : ''; $toString = ($match[2] > '') ? $match[2].'!' : '';
@ -753,7 +753,7 @@ class PHPExcel_ReferenceHelper
$cellIndex = $column.$row; $cellIndex = $column.$row;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString);
$cellTokens[$cellIndex] = '/(?<![A-Z])'.preg_quote($fromString).'(?!\d)/i'; $cellTokens[$cellIndex] = '/(?<![A-Z\$\!])'.preg_quote($fromString).'(?!\d)/i';
++$adjustCount; ++$adjustCount;
} }
} }
@ -890,7 +890,6 @@ class PHPExcel_ReferenceHelper
// Verify which parts should be updated // Verify which parts should be updated
$updateColumn = (($newColumn{0} != '$') && ($beforeColumn{0} != '$') && $updateColumn = (($newColumn{0} != '$') && ($beforeColumn{0} != '$') &&
PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn)); PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn));
$updateRow = (($newRow{0} != '$') && ($beforeRow{0} != '$') && $updateRow = (($newRow{0} != '$') && ($beforeRow{0} != '$') &&
$newRow >= $beforeRow); $newRow >= $beforeRow);

View File

@ -29,6 +29,8 @@ Fixed in develop branch for release v1.8.0:
- Bugfix: (MBaker) - Style error with merged cells in PDF Writer - Bugfix: (MBaker) - Style error with merged cells in PDF Writer
- Bugfix: (MBaker) - Problem with cloning worksheets - Bugfix: (MBaker) - Problem with cloning worksheets
- Bugfix: (tavoarcila) Work Item GH-259 - Bug fix reading Open Office files - Bugfix: (tavoarcila) Work Item GH-259 - Bug fix reading Open Office files
- Bugfix: (MBaker) Work item 20397 - Serious bug in absolute cell reference used in shared formula
Would also have affected insert/delete column/row
- Feature: (amerov) - Implementation of the Excel HLOOKUP() function - Feature: (amerov) - Implementation of the Excel HLOOKUP() function
- Feature: (MBaker) - Added "Quote Prefix" to style settings (Excel2007 Reader and Writer only) - Feature: (MBaker) - Added "Quote Prefix" to style settings (Excel2007 Reader and Writer only)
- Feature: (MBaker) - Added Horizontal FILL alignment for Excel5 and Excel2007 Readers/Writers, and Horizontal DISTRIBUTED alignment for Excel2007 Reader/Writer - Feature: (MBaker) - Added Horizontal FILL alignment for Excel5 and Excel2007 Readers/Writers, and Horizontal DISTRIBUTED alignment for Excel2007 Reader/Writer