Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rank formula not working #3932

Open
johnaddisco opened this issue Mar 4, 2024 · 1 comment
Open

Rank formula not working #3932

johnaddisco opened this issue Mar 4, 2024 · 1 comment

Comments

@johnaddisco
Copy link

i am trying to rank students based on their total scores stored, say F9 to F20, and print the results in G9 to G20. I began to print the first rank in G9, but it was not working. i got an error. Please, I need your help. Thanks

sample code:
$rankFormula = '=RANK.EQ(F9, $F$9:$F$20, 0)';
$sheet1->setCellValue('G9', $rankFormula);
$sheet1->getCell('G9')->getCalculatedValue();

Error:
Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Calculation\Exception: Sheet1!G9 -> Formula Error: Unexpected , in C:\xampp\htdocs\phpSpreadsheet\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Cell\Cell.php:277 Stack trace: #0 C:\xampp\htdocs\phpSpreadsheet\linksheet.php(31): PhpOffice\PhpSpreadsheet\Cell\Cell->getCalculatedValue() #1 {main} thrown in C:\xampp\htdocs\phpSpreadsheet\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Cell\Cell.php on line 277

@oleibman
Copy link
Collaborator

Unable to duplicate.

$spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet1 = $spreadsheet->getActiveSheet();
$sheet1->getCell('F9')->setValue(78);
$sheet1->getCell('F10')->setValue(82);
$sheet1->getCell('F11')->setValue(80);
$sheet1->getCell('F12')->setValue(63);
$sheet1->getCell('F13')->setValue(95);
$sheet1->getCell('F14')->setValue(86);
$sheet1->getCell('F15')->setValue(86);
$sheet1->getCell('F16')->setValue(82);
$sheet1->getCell('F17')->setValue(79);
$sheet1->getCell('F18')->setValue(73);
$sheet1->getCell('F19')->setValue(48);
$sheet1->getCell('F20')->setValue(53);

$rankFormula = '=RANK.EQ(F9,$F$9:$F$20,0)';
$sheet1->getcell('G9')->setValue($rankFormula);
var_dump($sheet1->getCell('G9')->getCalculatedValue());

Result:

int(8)

That matches Excel (as well as not throwing an exception).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants