From 7505638dc864a127e1b25ad605091e13500b6ed2 Mon Sep 17 00:00:00 2001 From: Juluan Date: Sun, 14 Jul 2019 12:56:17 +0200 Subject: [PATCH] Fix 1055 (#1076) * Fix #1055 : Make hlookup require ordered list only if asking for not exact match * Added test for #1055 --- src/PhpSpreadsheet/Calculation/LookupRef.php | 6 ++++-- tests/data/Calculation/LookupRef/HLOOKUP.php | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php index e6b0f320..f2d22c00 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef.php @@ -794,8 +794,10 @@ class LookupRef $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; } diff --git a/tests/data/Calculation/LookupRef/HLOOKUP.php b/tests/data/Calculation/LookupRef/HLOOKUP.php index 25bcea87..6a87a5a1 100644 --- a/tests/data/Calculation/LookupRef/HLOOKUP.php +++ b/tests/data/Calculation/LookupRef/HLOOKUP.php @@ -284,5 +284,15 @@ return [ ], 2, false - ] + ], + [ + 2, + 'B', + [ + ['Selection column', 'C', 'B', 'A'], + ['Value to retrieve', 3, 2, 1] + ], + 2, + false + ], ];