PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.2k forks source link

HLOOKUP row_index_num fix #1339

Closed ioulian closed 6 years ago

ioulian commented 6 years ago

There's a bug in the HLOOKUP function.

There is a check if $index_number is greater than the number of rows and fail if it's greater. Now due to copy pasting (I think) of the VLOOKUP function there is a check on the count of the COLUMNS and not ROWS:

Original:

$index_number > count($lookup_array[$firstRow])

We must check on the count of the rows (row_index_num and not col_index_num as in VLOOKUP) and not on the columns. So by changing the code to this, it works:

$index_number > count($lookup_array)

Full line: https://github.com/PHPOffice/PHPExcel/blob/185bf412339526c97a98d959c3c0ecf4b7c80016/Classes/PHPExcel/Calculation/LookupRef.php#L774

must be this:

if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array))) {
PowerKiKi commented 6 years ago

Thank you for reporting in details.

Next time please consider contributing a PR on PhpSpreadsheet develop branch.