Ask questionsHLookup::hLookupSearch(..) sends wrong arguments to LookupBase::checkMatch(..).
This is:
- [X] a bug report
Calling $cell->getCalculatedValue() ($cell is instance of PhpOffice\PhpSpreadsheet\Cell) should work but it fails with the latest master.
After $cell->getCalculatedValue() is called, the program fails with following error:
TypeError : PhpOffice\PhpSpreadsheet\Calculation\LookupRef\LookupBase::checkMatch(): Argument #4 ($rowKey) must be of type int, string given, called in
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php on line 74
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php:25
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:74
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:45
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:4776
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3469
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3262
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:259
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:5192
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:4669
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3469
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3262
xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:259
Here is the $cell variable value before $cell->getCalculatedValue() is called:

And here are the values from a breakpoint right before the error is triggered at
HLookup.php:73, PhpOffice\PhpSpreadsheet\Calculation\LookupRef\HLookup::hLookupSearch()

Unfortunately, I cannot simply share the the excel file that fails because it is from one of our customers but let me know if any more information is needed apart from what was shared above. ;-)
Tested on current master branch with PHP 8.0 and 7.4.
Answer
questions
majermi4
This is still and issue for us so I created a test excel sheet to demonstrate the problem.
Running this code:
$spreadsheet = IOFactory::load('./hlookup-test.xlsx');
$sheet = $spreadsheet->getSheet(0);
$cellVal = $sheet->getCell('H8')->getCalculatedValue();
On this excel spreadsheet: hlookup-test.xlsx

Results in:
TypeError {#3754
#message: "Argument 4 passed to PhpOffice\PhpSpreadsheet\Calculation\LookupRef\LookupBase::checkMatch() must be of the type int, string given, called in xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php on line 74"
#code: 0
#file: "./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php"
#line: 25
trace: {
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php:25 { …}
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:74 { …}
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:45 { …}
PhpOffice\PhpSpreadsheet\Calculation\LookupRef\HLookup::lookup() {}
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:4846 { …}
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3539 { …}
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3332 { …}
./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:259 { …}
./src/MyNamespace/Command/TestExcel.php:30 {
MyNamespace\Command\TestExcel->execute(InputInterface $input, OutputInterface $output): void
› $sheet = $spreadsheet->getSheet(0);
› $cellVal = $sheet->getCell('H8')->getCalculatedValue();
›
}
ping @MarkBaker let me know if I should provide any more information ;-)
Related questions