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

Resolve default values when a null argument is passed for HLOOKUP(), VLOOKUP() and ADDRESS() functions #2121

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Removed

- Nothing.
- Use of `nb` rather than `no` as the locale language code for Norsk Bokmål.

### Fixed
- Resolve default values when a null argument is passed for HLOOKUP(), VLOOKUP() and ADDRESS() functions [Issue #2120](https://github.com/PHPOffice/PhpSpreadsheet/issues/2120) - [PR #2121](https://github.com/PHPOffice/PhpSpreadsheet/pull/2121)
- Fixed incorrect R1C1 to A1 subtraction formula conversion (`R[-2]C-R[2]C`) [Issue #2076](https://github.com/PHPOffice/PhpSpreadsheet/pull/2076) [PR #2086](https://github.com/PHPOffice/PhpSpreadsheet/pull/2086)
- Correctly handle absolute A1 references when converting to R1C1 format [PR #2060](https://github.com/PHPOffice/PhpSpreadsheet/pull/2060)
- Correct default fill style for conditional without a pattern defined [Issue #2035](https://github.com/PHPOffice/PhpSpreadsheet/issues/2035) [PR #2050](https://github.com/PHPOffice/PhpSpreadsheet/pull/2050)
Expand Down Expand Up @@ -109,7 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Deprecated

- Nothing.
- All Excel Function implementations in `Calculation\Database`, `Calculation\DateTime`, `Calculation\Engineering`, `Calculation\Financial`, `Calculation\Logical`, `Calculation\LookupRef`, `Calculation\MathTrig`, `Calculation\Statistical`, `Calculation\TextData` and `Calculation\Web` have been moved to dedicated classes for individual functions or groups of related functions. See the docblocks against all the deprecated methods for details of the new methods to call instead. At some point, these old classes will be deleted.

### Removed

Expand Down
352 changes: 202 additions & 150 deletions composer.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2240,11 +2240,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/DocumentGenerator.php

-
message: "#^Cannot access offset 0 on \\(int\\|string\\)\\.$#"
count: 2
path: src/PhpSpreadsheet/DocumentGenerator.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\HashTable\\:\\:getIndexForHashCode\\(\\) should return int but returns int\\|string\\|false\\.$#"
count: 1
Expand Down
3 changes: 2 additions & 1 deletion src/PhpSpreadsheet/Calculation/LookupRef/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static function cell($row, $column, $relativity = 1, $referenceStyle = tr
{
$row = Functions::flattenSingleValue($row);
$column = Functions::flattenSingleValue($column);
$relativity = Functions::flattenSingleValue($relativity);
$relativity = ($relativity === null) ? 1 : Functions::flattenSingleValue($relativity);
$referenceStyle = ($referenceStyle === null) ? true : Functions::flattenSingleValue($referenceStyle);
$sheetName = Functions::flattenSingleValue($sheetName);

if (($row < 1) || ($column < 1)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function lookup($lookupValue, $lookupArray, $indexNumber, $notExac
{
$lookupValue = Functions::flattenSingleValue($lookupValue);
$indexNumber = Functions::flattenSingleValue($indexNumber);
$notExactMatch = Functions::flattenSingleValue($notExactMatch);
$notExactMatch = ($notExactMatch === null) ? true : Functions::flattenSingleValue($notExactMatch);

try {
$indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
Expand Down
9 changes: 6 additions & 3 deletions src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Indirect
/**
* Determine whether cell address is in A1 (true) or R1C1 (false) format.
*
* @param mixed $a1fmt Expect bool Helpers::CELLADDRESS_USE_A1 or CELLADDRESS_USE_R1C1, but can be provided as numeric which is cast to bool
* @param mixed $a1fmt Expect bool Helpers::CELLADDRESS_USE_A1 or CELLADDRESS_USE_R1C1,
* but can be provided as numeric which is cast to bool
*/
private static function a1Format($a1fmt): bool
{
Expand Down Expand Up @@ -53,7 +54,8 @@ private static function validateAddress($cellAddress): string
* =INDIRECT(cellAddress, bool) where the bool argument is optional
*
* @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula)
* @param mixed $a1fmt Expect bool Helpers::CELLADDRESS_USE_A1 or CELLADDRESS_USE_R1C1, but can be provided as numeric which is cast to bool
* @param mixed $a1fmt Expect bool Helpers::CELLADDRESS_USE_A1 or CELLADDRESS_USE_R1C1,
* but can be provided as numeric which is cast to bool
* @param Cell $pCell The current cell (containing this formula)
*
* @return array|string An array containing a cell or range of cells, or a string on error
Expand Down Expand Up @@ -84,7 +86,8 @@ public static function INDIRECT($cellAddress, $a1fmt, Cell $pCell)
/**
* Extract range values.
*
* @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
* @return mixed Array of values in range if range contains more than one element.
* Otherwise, a single value is returned.
*/
private static function extractRequiredCells(?Worksheet $pSheet, string $cellAddress)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function lookup($lookupValue, $lookupArray, $indexNumber, $notExac
{
$lookupValue = Functions::flattenSingleValue($lookupValue);
$indexNumber = Functions::flattenSingleValue($indexNumber);
$notExactMatch = Functions::flattenSingleValue($notExactMatch);
$notExactMatch = ($notExactMatch === null) ? true : Functions::flattenSingleValue($notExactMatch);

try {
$indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
Expand Down
1 change: 1 addition & 0 deletions src/PhpSpreadsheet/DocumentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static function generateFunctionListByName(array $phpSpreadsheetFunctions
$result = "# Function list by name\n";
$lastAlphabet = null;
foreach ($phpSpreadsheetFunctions as $excelFunction => $functionInfo) {
/** @var string $excelFunction */
$lengths = [25, 31, 37];
if ($lastAlphabet !== $excelFunction[0]) {
$lastAlphabet = $excelFunction[0];
Expand Down
10 changes: 9 additions & 1 deletion tests/data/Calculation/LookupRef/ADDRESS.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@
"'EXCEL SHEET'!R2C3",
2,
3,
1,
null,
false,
'EXCEL SHEET',
],
[
"'EXCEL SHEET'!\$C\$2",
2,
3,
1,
null,
'EXCEL SHEET',
],
[
'#VALUE!',
-2,
Expand Down
28 changes: 28 additions & 0 deletions tests/data/Calculation/LookupRef/HLOOKUP.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,34 @@
3,
true,
],
[
5,
'B',
[
[
'Axles',
'Bearings',
'Bolts',
],
[
4,
4,
9,
],
[
5,
7,
10,
],
[
6,
8,
11,
],
],
3,
null,
],
[
11,
'Bolts',
Expand Down
15 changes: 15 additions & 0 deletions tests/data/Calculation/LookupRef/VLOOKUP.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,19 @@
3,
true,
],
[
'E',
0.52,
[
['Lower', 'Upper', 'Grade'],
[0.00, 0.44, 'F'],
[0.45, 0.54, 'E'],
[0.55, 0.64, 'D'],
[0.65, 0.74, 'C'],
[0.75, 0.84, 'B'],
[0.85, 1.00, 'A'],
],
3,
null,
],
];