Local clone of [PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet/)
Go to file
Owen Leibman c4895b9468
MATCH with a static array should return the position of the found value based on the values submitted.
Returns #N/A, unless the element searched for is at the end of the array.

The problem is in Calculation.php line 4231:
                    if (!is_array($functionCall)) {
                        foreach ($args as &$arg) {
                            $arg = Functions::flattenSingleValue($arg);
                        }
                        unset($arg);
                    }

I believe this code is intended to handle functions where PhpSpreadsheet just passes
the call on to PHP without implementing the code on its own, e.g. for atan or acos.
In the bug report, the following code fails:
  $flat_rate = "=MATCH(6,{4,5,6,2}, 0)";
  $sheet->getCell('A1')->setValue($flat_rate);
The expected value is 3, but the actual result is "#N/A".
The reason for this result is that the parser replaces the braces with calls
to the MKMATRIX internal function, whose value for functioncall was:
'self::MKMATRIX'. Since this isn't an array, the flattening code is executed,
and the unintended result occurs. The fix is to change the definition for
functioncall in that case to [__CLASS__, 'mkMatrix'], avoiding the flattening.

However, there is also another part to this bug. The flattening should be
returning the first entry in the array, but is in fact returning the last.
This explains why the bug report specified "unless ... end of the array".
I confirmed that Excel does use the first item in the array rather than the last,
e.g. =atan({1,2,3}) entered into a cell will return atan(1), not atan(3).
The problem here is that flattenSingleValue, which says in its comments that
it is supposed to be returning the first item, uses array_pop rather than array_shift.
I have changed that as well. The same mistake was also present in
Cell.php function getCalculatedValue. The correct behavior can be verified
by entering =minverse({-2.5,1.5;2,-1}) into an Excel cell'
Excel flattens the result ({2,3;4,5}) to 2, and so should PhpSpreadsheet.

Fixes #1271
Closes #1332
2020-04-26 22:09:31 +09:00
.github Prefer https:// URLs when available in docs & comments 2018-10-28 13:55:00 +11:00
bin improve testability 2020-02-24 23:24:47 +09:00
docs Replace Sami with phpDocumentor 3 2020-04-05 17:47:25 +09:00
samples Drop PHP 5.6 and 7.0 2019-07-24 23:12:45 -07:00
src MATCH with a static array should return the position of the found value based on the values submitted. 2020-04-26 22:09:31 +09:00
tests MATCH with a static array should return the position of the found value based on the values submitted. 2020-04-26 22:09:31 +09:00
.gitattributes Do not export .github folder (#1211) 2019-10-19 13:18:28 +02:00
.gitignore Move PHP-CS-Fixer cache file out of the project to avoid IDE annoyance 2018-10-21 15:34:33 +11:00
.php_cs.dist Take advantage of PHP 7.1 syntax 2019-07-24 23:43:28 -07:00
.scrutinizer.yml Revert "Accept no change of coverage" 2017-12-23 20:59:18 +09:00
.travis.yml Replace Sami with phpDocumentor 3 2020-04-05 17:47:25 +09:00
CHANGELOG.PHPExcel.md Prefer https:// URLs when available in docs & comments 2018-10-28 13:55:00 +11:00
CHANGELOG.md MATCH with a static array should return the position of the found value based on the values submitted. 2020-04-26 22:09:31 +09:00
CONTRIBUTING.md `master` is the new default branch 2019-01-02 15:28:38 +11:00
LICENSE Change license from LGPL 2.1 to MIT 2019-11-17 18:08:34 +01:00
README.md Replace Sami with phpDocumentor 3 2020-04-05 17:47:25 +09:00
composer.json Change license from LGPL 2.1 to MIT 2019-11-17 18:08:34 +01:00
composer.lock PHP 7.4 compatibility 2019-11-30 00:12:46 +01:00
mkdocs.yml `master` is the new default branch 2019-01-02 15:28:38 +11:00
phpunit.xml.dist Upgrade to phpunit 7.5 2019-07-24 23:45:43 -07:00

README.md

PhpSpreadsheet

Build Status Code Quality Code Coverage Total Downloads Latest Stable Version License Join the chat at https://gitter.im/PHPOffice/PhpSpreadsheet

PhpSpreadsheet is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.

Documentation

Read more about it, including install instructions, in the official documentation. Or check out the API documentation.

Please ask your support questions on StackOverflow, or have a quick chat on Gitter.

PHPExcel vs PhpSpreadsheet ?

PhpSpreadsheet is the next version of PHPExcel. It breaks compatibility to dramatically improve the code base quality (namespaces, PSR compliance, use of latest PHP language features, etc.).

Because all efforts have shifted to PhpSpreadsheet, PHPExcel will no longer be maintained. All contributions for PHPExcel, patches and new features, should target PhpSpreadsheet master branch.

License

PhpSpreadsheet is licensed under MIT.