From 6faed3bd585b646935488f80f75eea59261934f5 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 19 May 2016 14:38:50 +0200 Subject: [PATCH] #463 : Patch @domic-olga vlookup - incorrect value when not exact match --- src/PhpSpreadsheet/Calculation/LookupRef.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php index f5553af4..359fa164 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef.php @@ -720,8 +720,12 @@ class LookupRef (!is_numeric($lookup_value) && !is_numeric($rowData[$firstColumn]) && (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)))) { break; } - $rowNumber = $rowKey; - $rowValue = $rowData[$firstColumn]; + // remember the last key, but only if datatypes match + if ((is_numeric($lookup_value) && is_numeric($rowData[$firstColumn])) || + (!is_numeric($lookup_value) && !is_numeric($rowData[$firstColumn]))) { + $rowNumber = $rowKey; + $rowValue = $rowData[$firstColumn]; + } } if ($rowNumber !== false) {