Skip to content

Commit ef5a241

Browse files
author
yunjusu
committed
fix getCalculatedValue
1 parent 34675bd commit ef5a241

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2828
- Best effort to support invalid colspan values in HTML reader - [878](https://github.com/PHPOffice/PhpSpreadsheet/pull/878)
2929
- Fixes incorrect rows deletion [#868](https://github.com/PHPOffice/PhpSpreadsheet/issues/868)
3030
- MATCH function fix (value search by type, stop search when match_type=-1 and unordered element encountered) - [Issue #1116](https://github.com/PHPOffice/PhpSpreadsheet/issues/1116)
31+
- Fix getCalculatedValue error with more than two INDIRECT
3132

3233
## [1.8.2] - 2019-07-08
3334

src/PhpSpreadsheet/Calculation/Calculation.php

+4
Original file line numberDiff line numberDiff line change
@@ -4140,6 +4140,9 @@ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null)
41404140

41414141
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
41424142
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/i', $token, $matches)) {
4143+
if ($pCellParent) {
4144+
$pCell->attach($pCellParent);
4145+
}
41434146
if (($cellID == 'AC99') || (isset($pCell) && $pCell->getCoordinate() == 'AC99')) {
41444147
if (defined('RESOLVING')) {
41454148
define('RESOLVING2', true);
@@ -4215,6 +4218,7 @@ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null)
42154218
}
42164219
unset($arg);
42174220
}
4221+
42184222
$result = call_user_func_array($functionCall, $args);
42194223

42204224
if ($functionName != 'MKMATRIX') {

tests/PhpSpreadsheetTests/Calculation/CalculationTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ public function testCellWithDdeExpresion()
164164
self::assertEquals("=cmd|'/C calc'!A0", $cell->getCalculatedValue());
165165
}
166166

167+
public function testCellWithFormulaTwoIndirect()
168+
{
169+
$spreadsheet = new Spreadsheet();
170+
$workSheet = $spreadsheet->getActiveSheet();
171+
$cell1 = $workSheet->getCell('A1');
172+
$cell1->setValue('2');
173+
$cell2 = $workSheet->getCell('B1');
174+
$cell2->setValue('3');
175+
$cell3 = $workSheet->getCell('C1');
176+
$cell3->setValue('=INDIRECT("A"&ROW())+INDIRECT("B"&ROW())');
177+
178+
self::assertEquals("5", $cell3->getCalculatedValue());
179+
}
180+
167181
public function testBranchPruningFormulaParsingSimpleCase()
168182
{
169183
$calculation = Calculation::getInstance();

0 commit comments

Comments
 (0)