Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, int> $d */
Expand Down
38 changes: 38 additions & 0 deletions tests/PhpSpreadsheetTests/Calculation/Issue4656Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Calculation;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

class Issue4656Test extends TestCase
{
public function testIssue4656(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->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();
}
}