Skip to content

Commit

Permalink
fix getCalculatedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
yunjusu committed Aug 14, 2019
1 parent 34675bd commit 5fa9fd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Best effort to support invalid colspan values in HTML reader - [878](/~https://github.com/PHPOffice/PhpSpreadsheet/pull/878)
- Fixes incorrect rows deletion [#868](/~https://github.com/PHPOffice/PhpSpreadsheet/issues/868)
- 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)
- Fix getCalculatedValue error with more than two INDIRECT

## [1.8.2] - 2019-07-08

Expand Down
4 changes: 4 additions & 0 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4140,6 +4140,9 @@ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null)

// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/i', $token, $matches)) {
if ($pCellParent) {
$pCell->attach($pCellParent);
}
if (($cellID == 'AC99') || (isset($pCell) && $pCell->getCoordinate() == 'AC99')) {
if (defined('RESOLVING')) {
define('RESOLVING2', true);
Expand Down Expand Up @@ -4215,6 +4218,7 @@ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null)
}
unset($arg);
}

$result = call_user_func_array($functionCall, $args);

if ($functionName != 'MKMATRIX') {
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpSpreadsheetTests/Calculation/CalculationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ public function testCellWithDdeExpresion()
self::assertEquals("=cmd|'/C calc'!A0", $cell->getCalculatedValue());
}

public function testCellWithFormulaTwoIndirect()
{
$spreadsheet = new Spreadsheet();
$workSheet = $spreadsheet->getActiveSheet();
$cell1 = $workSheet->getCell('A1');
$cell1->setValue('2');
$cell2 = $workSheet->getCell('B1');
$cell2->setValue('3');
$cell2 = $workSheet->getCell('C1');
$cell2->setValue('4');
$cell3 = $workSheet->getCell('D1');
$cell3->setValue('=SUM(INDIRECT("A"&ROW()),INDIRECT("B"&ROW()),INDIRECT("C"&ROW()))');

self::assertEquals('9', $cell3->getCalculatedValue());
}

public function testBranchPruningFormulaParsingSimpleCase()
{
$calculation = Calculation::getInstance();
Expand Down

0 comments on commit 5fa9fd8

Please sign in to comment.