Bugfix: Work Item GH-275 - Insert New Row/Column Before is not correctly updating formula references

This commit is contained in:
Mark Baker 2013-12-09 22:33:45 +00:00
parent 7a90c5b888
commit e79181cb4d
2 changed files with 6 additions and 8 deletions

View File

@ -431,6 +431,7 @@ class PHPExcel_ReferenceHelper
while ($cellID = array_pop($aCellCollection)) { while ($cellID = array_pop($aCellCollection)) {
$cell = $pSheet->getCell($cellID); $cell = $pSheet->getCell($cellID);
$cellIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn()); $cellIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn());
if ($cellIndex-1 + $pNumCols < 0) { if ($cellIndex-1 + $pNumCols < 0) {
continue; continue;
} }
@ -736,6 +737,7 @@ class PHPExcel_ReferenceHelper
} }
// Search for cell references (e.g. 'Sheet1'!A3 or C5) with or without $ absolutes (e.g. $A1 or C$5) // Search for cell references (e.g. 'Sheet1'!A3 or C5) with or without $ absolutes (e.g. $A1 or C$5)
$matchCount = preg_match_all('/'.self::REFHELPER_REGEXP_CELLREF.'/i', ' '.$formulaBlock.' ', $matches, PREG_SET_ORDER); $matchCount = preg_match_all('/'.self::REFHELPER_REGEXP_CELLREF.'/i', ' '.$formulaBlock.' ', $matches, PREG_SET_ORDER);
if ($matchCount > 0) { if ($matchCount > 0) {
foreach($matches as $match) { foreach($matches as $match) {
$fromString = ($match[2] > '') ? $match[2].'!' : ''; $fromString = ($match[2] > '') ? $match[2].'!' : '';
@ -750,7 +752,7 @@ class PHPExcel_ReferenceHelper
// 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 // 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 = PHPExcel_Cell::columnIndexFromString(trim($column,'$')) + 100000; $column = PHPExcel_Cell::columnIndexFromString(trim($column,'$')) + 100000;
$row = trim($row,'$') + 10000000; $row = trim($row,'$') + 10000000;
$cellIndex = $column.$row; $cellIndex = $row . $column;
$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';
@ -760,13 +762,8 @@ class PHPExcel_ReferenceHelper
} }
} }
if ($adjustCount > 0) { if ($adjustCount > 0) {
if ($pNumCols > 0) { krsort($cellTokens);
krsort($cellTokens); krsort($newCellTokens);
krsort($newCellTokens);
} else {
ksort($cellTokens);
ksort($newCellTokens);
}
// Update cell references in the formula // Update cell references in the formula
$formulaBlock = str_replace('\\','',preg_replace($cellTokens,$newCellTokens,$formulaBlock)); $formulaBlock = str_replace('\\','',preg_replace($cellTokens,$newCellTokens,$formulaBlock));
} }

View File

@ -39,6 +39,7 @@ Fixed in develop branch for release v1.8.0:
- Bugfix: (IndrekHaav) Work Item CP16208 - Fixed undefined variable error due to $styleArray being used before it's initialised - Bugfix: (IndrekHaav) Work Item CP16208 - Fixed undefined variable error due to $styleArray being used before it's initialised
- Bugfix: (PowerKiKi) Work Item GH-273 - ISTEXT() return wrong result if referencing an empty but formatted cell - Bugfix: (PowerKiKi) Work Item GH-273 - ISTEXT() return wrong result if referencing an empty but formatted cell
- Bugfix: (PowerKiKi) Work Item GH-270/GH-31 - Binary comparison of strings are case insensitive - Bugfix: (PowerKiKi) Work Item GH-270/GH-31 - Binary comparison of strings are case insensitive
- Bugfix: (MBaker) Work Item GH-275 - Insert New Row/Column Before is not correctly updating formula references
- 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