diff --git a/Classes/PHPExcel/Calculation.php b/Classes/PHPExcel/Calculation.php index f6060882..51cbbbcb 100644 --- a/Classes/PHPExcel/Calculation.php +++ b/Classes/PHPExcel/Calculation.php @@ -3652,9 +3652,17 @@ class PHPExcel_Calculation { $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet); if (!is_null($namedRange)) { $pSheet = $namedRange->getWorksheet(); -//// echo 'Named Range '.$pRange.' ('; +// echo 'Named Range '.$pRange.' ('; $pRange = $namedRange->getRange(); -//// echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'
'; + $splitRange = PHPExcel_Cell::splitRange($pRange); + // Convert row and column references + if (ctype_alpha($splitRange[0][0])) { + $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow(); + } elseif(ctype_digit($splitRange[0][0])) { + $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1]; + } +// echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'
'; + // if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) { // if (!$namedRange->getLocalOnly()) { // $pSheet = $namedRange->getWorksheet(); @@ -3668,8 +3676,9 @@ class PHPExcel_Calculation { // Extract range $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange); +// var_dump($aReferences); if (!isset($aReferences[1])) { - // Single cell in range + // Single cell (or single column or row) in range list($currentCol,$currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]); if ($pSheet->cellExists($aReferences[0])) { $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog); diff --git a/Classes/PHPExcel/ReferenceHelper.php b/Classes/PHPExcel/ReferenceHelper.php index 4ccc2b59..206ad9e8 100644 --- a/Classes/PHPExcel/ReferenceHelper.php +++ b/Classes/PHPExcel/ReferenceHelper.php @@ -545,7 +545,7 @@ class PHPExcel_ReferenceHelper /** * Update cell range * - * @param string $pCellRange Cell range + * @param string $pCellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3') * @param int $pBefore Insert before this one * @param int $pNumCols Number of columns to increment * @param int $pNumRows Number of rows to increment @@ -560,7 +560,15 @@ class PHPExcel_ReferenceHelper for ($i = 0; $i < $ic; ++$i) { $jc = count($range[$i]); for ($j = 0; $j < $jc; ++$j) { - $range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); + if (ctype_alpha($range[$i][$j])) { + $r = PHPExcel_Cell::coordinateFromString($this->_updateSingleCellReference($range[$i][$j].'1', $pBefore, $pNumCols, $pNumRows)); + $range[$i][$j] = $r[0]; + } elseif(ctype_digit($range[$i][$j])) { + $r = PHPExcel_Cell::coordinateFromString($this->_updateSingleCellReference('A'.$range[$i][$j], $pBefore, $pNumCols, $pNumRows)); + $range[$i][$j] = $r[1]; + } else { + $range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); + } } } diff --git a/Classes/PHPExcel/Writer/Excel2007/Workbook.php b/Classes/PHPExcel/Writer/Excel2007/Workbook.php index 83414581..3668779f 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Workbook.php +++ b/Classes/PHPExcel/Writer/Excel2007/Workbook.php @@ -321,9 +321,9 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write // Create absolute coordinate and write as raw text $range = PHPExcel_Cell::splitRange($pNamedRange->getRange()); for ($i = 0; $i < count($range); $i++) { - $range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteCoordinate($range[$i][0]); + $range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteReference($range[$i][0]); if (isset($range[$i][1])) { - $range[$i][1] = PHPExcel_Cell::absoluteCoordinate($range[$i][1]); + $range[$i][1] = PHPExcel_Cell::absoluteReference($range[$i][1]); } } $range = PHPExcel_Cell::buildRange($range); diff --git a/changelog.txt b/changelog.txt index 5a90160f..21c4c555 100644 --- a/changelog.txt +++ b/changelog.txt @@ -68,6 +68,7 @@ Fixed in SVN: - Bugfix: (MBaker) Work item 15096 - insertNewRowBefore fails to consistently update references - Bugfix: (MBaker) "i" is not a valid character for Excel date format masks (in isDateTimeFormatCode() method) - Bugfix: (MKunert) Work item 15421 - PHPExcel_ReferenceHelper::insertNewBefore() is missing an 'Update worksheet: comments' section +- Bugfix: (MBaker) Work item 15409 - Full column/row references in named ranges not supported by updateCellReference() - General: (MBaker) Improved performance (speed), for building the Shared Strings table in the Excel2007 Writer. - General: (MBaker) Improved performance (speed), for PHP to Excel date conversions - General: (MBaker) Enhanced SheetViews element structures in the Excel2007 Writer for frozen panes.