Fix `getCalculatedValue()` error with more than two INDIRECT

Closes #1115
This commit is contained in:
yunjusu 2019-07-30 17:04:15 +08:00 committed by Adrien Crivelli
parent 95c8bb9918
commit bbbfdb86a0
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 21 additions and 0 deletions

View File

@ -29,6 +29,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 [#1115](https://github.com/PHPOffice/PhpSpreadsheet/pull/1115)
## [1.8.2] - 2019-07-08

View File

@ -4140,6 +4140,9 @@ class Calculation
// 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);
@ -4215,6 +4218,7 @@ class Calculation
}
unset($arg);
}
$result = call_user_func_array($functionCall, $args);
if ($functionName != 'MKMATRIX') {

View File

@ -164,6 +164,22 @@ class CalculationTest extends TestCase
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();