From 87be8d3d8e1c503a6422fee585e5fc5193c66978 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 15 Jul 2014 23:33:06 +0100 Subject: [PATCH] Bugfix to ensure that current cell is maintained when executing formula calculations --- Classes/PHPExcel/Calculation.php | 10 ++++++++++ changelog.txt | 1 + 2 files changed, 11 insertions(+) diff --git a/Classes/PHPExcel/Calculation.php b/Classes/PHPExcel/Calculation.php index c4f21129..c159012b 100644 --- a/Classes/PHPExcel/Calculation.php +++ b/Classes/PHPExcel/Calculation.php @@ -194,6 +194,8 @@ class PHPExcel_Calculation { */ private $_cyclicReferenceStack; + private $_cellStack = array(); + /** * Current iteration counter for cyclic formulae * If the value is 0 (or less) then cyclic formulae will throw an exception, @@ -2240,9 +2242,17 @@ class PHPExcel_Calculation { } // Execute the calculation for the cell formula + $this->_cellStack[] = array( + 'sheet' => $pCell->getWorksheet()->getTitle(), + 'cell' => $pCell->getCoordinate(), + ); try { $result = self::_unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell)); + $cellAddress = array_pop($this->_cellStack); + $this->_workbook->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']); } catch (PHPExcel_Exception $e) { + $cellAddress = array_pop($this->_cellStack); + $this->_workbook->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']); throw new PHPExcel_Calculation_Exception($e->getMessage()); } diff --git a/changelog.txt b/changelog.txt index 17e2bb0d..cb30111e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -25,6 +25,7 @@ Planned for v1.8.1 - Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula - Bugfix: (sarciszewski) Work Item GH-329 - Avoid potential divide by zero in basedrawing +- Bugfix: (MBaker) - Fix to ensure that current cell is maintained when executing formula calculations - General: (MBaker) - Small performance improvement for autosize columns - Feature: (WiktrzGE) Work Item GH-404 - Methods to manage most of the existing options for Chart Axis, Major Grid-lines and Minor Grid-lines - Feature: (frost-nzcr4) Work Item GH-403 - ODS read/write comments in the cell