diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index abdd4c811a..0d502e1817 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -1236,16 +1236,14 @@ private function internalParseFormula(string $formula, ?Cell $cell = null): bool // because at least the braces are paired up (at this stage in the formula) // MS Excel allows this if the content is cell references; but doesn't allow actual values, // but at this point, we can't differentiate (so allow both) - return $this->raiseFormulaError('Formula Error: Unexpected ,'); - /* The following code may be a better choice, but, with - the other changes for this PR, I can no longer come up - with a test case that gets here + //return $this->raiseFormulaError('Formula Error: Unexpected ,'); + $stack->push('Binary Operator', '∪'); ++$index; $expectingOperator = false; - continue;*/ + continue; } /** @var array $d */ diff --git a/tests/PhpSpreadsheetTests/Calculation/Issue4656Test.php b/tests/PhpSpreadsheetTests/Calculation/Issue4656Test.php new file mode 100644 index 0000000000..c4e2df933d --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Issue4656Test.php @@ -0,0 +1,38 @@ +getActiveSheet(); + $sheet->setCellValue('B1', 2); + $sheet->setCellValue('C1', 1); + $sheet->setCellValue('D1', 3); + $sheet->setCellValue('E1', 2); + $sheet->setCellValue('A1', '=RANK(B1,(C1,E1))'); + $sheet->setCellValue('A2', '=RANK(B1,C1:E1)'); + self::assertSame(1, $sheet->getCell('A1')->getCalculatedValue()); + self::assertSame(2, $sheet->getCell('A2')->getCalculatedValue()); + $spreadsheet->disconnectWorksheets(); + } + + public function testIssue4656Original(): void + { + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $sheet->setCellValue('B1', 1); + $sheet->setCellValue('C1', 1); + $sheet->setCellValue('D1', 2); + $sheet->setCellValue('A1', '=RANK(B1,(C1,D1))'); + self::assertSame(2, $sheet->getCell('A1')->getCalculatedValue()); + $spreadsheet->disconnectWorksheets(); + } +}