Fix HLOOKUP on single row (#1512)
Fixes a bug when doing a HLOOKUP on a single row. ```php <?php require 'vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\Spreadsheet; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); /** * Single row. */ $singleRow = "=HLOOKUP(10, {5, 10, 15}, 1, 0)"; $sheet->getCell('A1')->setValue($singleRow); // Should echo 10, but echos '#N/A' and some PHP notices and warnings. echo $sheet->getCell('A1')->getCalculatedValue() . PHP_EOL; /** * Multiple rows. */ $multipleRows = "=HLOOKUP(10, {5, 10, 15; 20, 25, 30}, 1, 0)"; $sheet->getCell('A2')->setValue($multipleRows); // Should echo: 10 and also does. echo $sheet->getCell('A2')->getCalculatedValue() . PHP_EOL; ``` Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
This commit is contained in:
parent
38fab4e632
commit
a5a0268050
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Resolve evaluation of utf-8 named ranges in calculation engine [#1522](https://github.com/PHPOffice/PhpSpreadsheet/pull/1522)
|
- Resolve evaluation of utf-8 named ranges in calculation engine [#1522](https://github.com/PHPOffice/PhpSpreadsheet/pull/1522)
|
||||||
|
- Fix HLOOKUP on single row [#1512](https://github.com/PHPOffice/PhpSpreadsheet/pull/1512)
|
||||||
- Fix MATCH when comparing different numeric types [#1521](https://github.com/PHPOffice/PhpSpreadsheet/pull/1521)
|
- Fix MATCH when comparing different numeric types [#1521](https://github.com/PHPOffice/PhpSpreadsheet/pull/1521)
|
||||||
- Fix exact MATCH on ranges with empty cells [#1520](https://github.com/PHPOffice/PhpSpreadsheet/pull/1520)
|
- Fix exact MATCH on ranges with empty cells [#1520](https://github.com/PHPOffice/PhpSpreadsheet/pull/1520)
|
||||||
|
|
||||||
|
|
|
@ -807,7 +807,7 @@ class LookupRef
|
||||||
return Functions::REF();
|
return Functions::REF();
|
||||||
}
|
}
|
||||||
$f = array_keys($lookup_array);
|
$f = array_keys($lookup_array);
|
||||||
$firstRow = array_pop($f);
|
$firstRow = reset($f);
|
||||||
if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array))) {
|
if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array))) {
|
||||||
return Functions::REF();
|
return Functions::REF();
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,6 +275,19 @@ return [
|
||||||
2,
|
2,
|
||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
5,
|
5,
|
||||||
'x',
|
'x',
|
||||||
|
|
Loading…
Reference in New Issue