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

MATCH function #1116

Closed
1 task done
rolandsusans opened this issue Jul 30, 2019 · 1 comment
Closed
1 task done

MATCH function #1116

rolandsusans opened this issue Jul 30, 2019 · 1 comment

Comments

@rolandsusans
Copy link
Contributor

rolandsusans commented Jul 30, 2019

This is:

  • a bug report

In some case currently implemented MATCH function produces a different result from original MS Excel implementation. See red ones in these screenshots:

Screenshot 2019-07-30 at 16 36 03
Screenshot 2019-07-30 at 17 48 54

The file can be found here.

The bug is related to:

  • not correctly handling boolean values ( conversion to string should be done only when the value is a string )
  • match_type = -1, error when firs element is different data type and < value being searched
  • match_type = -1 when at least one element in lookup array found, but the next element is less than the searched value ( unordered list ) is being checked till the end.
  • not supporting *?~ Excel functionality

How MATCH function should work:

MS Excel docs here.

Match type  
-1 MATCH finds the smallest value that is greater than or equal tolookup_value. The values in the lookup_array argument must be placed in descending order, for example: TRUE, FALSE, Z-A, ...2, 1, 0, -1, -2, ..., and so on.
0 MATCH finds the first value that is exactly equal to lookup_value. The values in the lookup_array argument can be in any order.
1 MATCH finds the largest value that is less than or equal to lookup_value. The values in the lookup_array argument must be placed in ascending order, for example: ...-2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE.

MATCH does not distinguish between uppercase and lowercase letters when matching text values.

If match_type is 0 and lookup_value is a text string, you can use the wildcard characters — the question mark (?) and asterisk (*) — in the lookup_value argument. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.

What is the expected behaviour?

Expected behaviour listed in E column. ( calculated by opening the worksheet in Excel for MAC 16.26 )

What is the current behaviour?

Current behaviour listed in G column. Calculated using PHP script using the library. ( Calculate E and store the result into G ).

What are the steps to reproduce?

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';

var_dump(\PhpOffice\PhpSpreadsheet\Calculation\LookupRef::MATCH(TRUE, [TRUE, FALSE], 0));//#N/A intedad of 1
 var_dump(\PhpOffice\PhpSpreadsheet\Calculation\LookupRef::MATCH('a*b', ['acb'], 0));//#N/A instedad of 1

Which versions of PhpSpreadsheet and PHP are affected?

  • "phpoffice/phpspreadsheet": "^1.6",
  • all versions of PHP
@rolandsusans
Copy link
Contributor Author

I will try to fix this one.

@rolandsusans rolandsusans mentioned this issue Jul 31, 2019
7 tasks
PowerKiKi added a commit that referenced this issue Aug 17, 2019
1.9.0

### Added

- When &lt;br&gt; appears in a table cell, set the cell to wrap [#1071](#1071) and [#1070](#1070)
- Add MAXIFS, MINIFS, COUNTIFS and Remove MINIF, MAXIF [#1056](#1056)
- HLookup needs an ordered list even if range_lookup is set to false [#1055](#1055) and [#1076](#1076)
- Improve performance of IF function calls via ranch pruning to avoid resolution of every branches [#844](#844)
- MATCH function supports `*?~` Excel functionality, when match_type=0 [#1116](#1116)
- Allow HTML Reader to accept HTML as a string [#1136](#1136)

### Fixed

- Fix to AVERAGEIF() function when called with a third argument
- Eliminate duplicate fill none style entries [#1066](#1066)
- Fix number format masks containing literal (non-decimal point) dots [#1079](#1079)
- Fix number format masks containing named colours that were being misinterpreted as date formats; and add support for masks that fully replace the value with a full text string [#1009](#1009)
- Stricter-typed comparison testing in COUNTIF() and COUNTIFS() evaluation [#1046](#1046)
- COUPNUM should not return zero when settlement is in the last period [#1020](#1020) and [#1021](#1021)
- Fix handling of named ranges referencing sheets with spaces or "!" in their title
- Cover `getSheetByName()` with tests for name with quote and spaces [#739](#739)
- Best effort to support invalid colspan values in HTML reader - [#878](#878)
- Fixes incorrect rows deletion [#868](#868)
- MATCH function fix (value search by type, stop search when match_type=-1 and unordered element encountered) [#1116](#1116)
- Fix `getCalculatedValue()` error with more than two INDIRECT [#1115](#1115)
- Writer\Html did not hide columns [#985](#985)
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

1 participant