PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.29k stars 3.44k forks source link

Formula Parsing Error Using Union Arguments #503

Open SlowFox71 opened 6 years ago

SlowFox71 commented 6 years ago

This is:

- [X] a bug report
- [ ] a feature request
- [X] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Parsing the this formula correctly: =RANK(B1,(C1,D1))

What is the current behavior?

Throwing an exception "Formula Error: Unexpected ,"

What are the steps to reproduce?

Create an Excel file with a formula like the above and try to read the cell content.

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValueExplicit('A1', '=RANK(B1, (C1, D1))', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA);
$value = $sheet->getCell('A1')->getCalculatedValue();

?>

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.0, PhpSpreadsheet 1.2.1

Please note that this is a valid formula; excel accepts lists of cells instead of ranges without complaining.

SlowFox71 commented 6 years ago

I've had a look at the sources now. There is Calculation\FormulaParser which seems to support this (TOKEN_SUBTYPE_UNION should do the trick), but the FormulaParser is not used anywhere in the rest of the code. Instead of there is a Method _parseFormula() in Calculation\Calculation, which is used but does not support unions.

Is Calculation\FormulaParser still work in progress and will be seen in later releases?

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

oleibman commented 2 months ago

Reopening. Do not expect a fix any time soon.