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

HLookup need an ordered list even if range_lookup is set to false #1055

Closed
jtattevin opened this issue Jul 3, 2019 · 0 comments
Closed

HLookup need an ordered list even if range_lookup is set to false #1055

jtattevin opened this issue Jul 3, 2019 · 0 comments

Comments

@jtattevin
Copy link
Contributor

jtattevin commented Jul 3, 2019

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

If range_lookup is FALSE (require exact match), values in the first row of table do not need to be sorted.

What is the current behavior?

HLOOKUP assume that the list is always sorted, so if the searched value is after a value bigger, the hlookup will return a #N/A

What are the steps to reproduce?

<?php

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

require 'vendor/autoload.php';

$spreadsheet=new Spreadsheet;
$workSheet = $spreadsheet->getActiveSheet();


$workSheet->setCellValue('A1', 'SMALL');
$workSheet->setCellValue('B1','MEDIUM');
$workSheet->setCellValue('C1', 'LARGE');

$workSheet->setCellValue('A2', '1');
$workSheet->setCellValue('B2','2');
$workSheet->setCellValue('C2', '3');


$workSheet->setCellValue('D1', 'LARGE');
$workSheet->setCellValue('D2', '=HLOOKUP(D1, A1:C2, 1, 0)');

echo $spreadsheet->getActiveSheet()->getCell('D2')->getCalculatedValue().PHP_EOL;
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('test.xls');

Which versions of PhpSpreadsheet and PHP are affected?

Tested with version 1.6, 1.8.1 and dev-master d4eab49

The lines causing this are https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Calculation/LookupRef.php#L797

@jtattevin jtattevin changed the title HLookup need an ordered list / Excel and libreoffice don't HLookup need an ordered list event if range_lookup is set to false Jul 3, 2019
jtattevin added a commit to jtattevin/PhpSpreadsheet that referenced this issue Jul 4, 2019
@jtattevin jtattevin changed the title HLookup need an ordered list event if range_lookup is set to false HLookup need an ordered list even if range_lookup is set to false Jul 4, 2019
jtattevin added a commit to jtattevin/PhpSpreadsheet that referenced this issue Jul 14, 2019
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