Skip to content

Commit 87be8d3

Browse files
author
MarkBaker
committed
Bugfix to ensure that current cell is maintained when executing formula calculations
1 parent c6d0a4d commit 87be8d3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Classes/PHPExcel/Calculation.php

+10
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ class PHPExcel_Calculation {
194194
*/
195195
private $_cyclicReferenceStack;
196196

197+
private $_cellStack = array();
198+
197199
/**
198200
* Current iteration counter for cyclic formulae
199201
* If the value is 0 (or less) then cyclic formulae will throw an exception,
@@ -2240,9 +2242,17 @@ public function calculateCellValue(PHPExcel_Cell $pCell = NULL, $resetLog = TRUE
22402242
}
22412243

22422244
// Execute the calculation for the cell formula
2245+
$this->_cellStack[] = array(
2246+
'sheet' => $pCell->getWorksheet()->getTitle(),
2247+
'cell' => $pCell->getCoordinate(),
2248+
);
22432249
try {
22442250
$result = self::_unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
2251+
$cellAddress = array_pop($this->_cellStack);
2252+
$this->_workbook->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
22452253
} catch (PHPExcel_Exception $e) {
2254+
$cellAddress = array_pop($this->_cellStack);
2255+
$this->_workbook->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
22462256
throw new PHPExcel_Calculation_Exception($e->getMessage());
22472257
}
22482258

changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Planned for v1.8.1
2626
- Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula
2727
- Bugfix: (sarciszewski) Work Item GH-329 - Avoid potential divide by zero in basedrawing
28+
- Bugfix: (MBaker) - Fix to ensure that current cell is maintained when executing formula calculations
2829
- General: (MBaker) - Small performance improvement for autosize columns
2930
- Feature: (WiktrzGE) Work Item GH-404 - Methods to manage most of the existing options for Chart Axis, Major Grid-lines and Minor Grid-lines
3031
- Feature: (frost-nzcr4) Work Item GH-403 - ODS read/write comments in the cell

0 commit comments

Comments
 (0)