Skip to content

Commit

Permalink
Fix 1055 (#1076)
Browse files Browse the repository at this point in the history
* Fix #1055 : Make hlookup require ordered list only if asking for not exact match

* Added test for #1055
  • Loading branch information
Juluan authored and Mark Baker committed Jul 14, 2019
1 parent 42fc71f commit 7505638
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/PhpSpreadsheet/Calculation/LookupRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,10 @@ public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not
$lookupLower = StringHelper::strToLower($lookup_value);
$rowDataLower = StringHelper::strToLower($rowData);

if (($bothNumeric && $rowData > $lookup_value) ||
($bothNotNumeric && $rowDataLower > $lookupLower)) {
if ($not_exact_match && (
($bothNumeric && $rowData > $lookup_value) ||
($bothNotNumeric && $rowDataLower > $lookupLower)
)) {
break;
}

Expand Down
12 changes: 11 additions & 1 deletion tests/data/Calculation/LookupRef/HLOOKUP.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,15 @@
],
2,
false
]
],
[
2,
'B',
[
['Selection column', 'C', 'B', 'A'],
['Value to retrieve', 3, 2, 1]
],
2,
false
],
];

0 comments on commit 7505638

Please sign in to comment.