Skip to content

Commit 0824fd5

Browse files
authored
Merge pull request #3868 from oleibman/issue3866
Excel Inconsistent Handling of Empty Argument MIN/MAX/MINA/MAXA
2 parents d50b8b5 + b5e3ca3 commit 0824fd5

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
9393
- Do not include unparsed drawings when new drawing added. [Issue #3861](https://github.com/PHPOffice/PhpSpreadsheet/issues/3861) [PR #3862](https://github.com/PHPOffice/PhpSpreadsheet/pull/3862)
9494
- Excel omits `between` operator for data validation. [Issue #3863](https://github.com/PHPOffice/PhpSpreadsheet/issues/3863) [PR #3865](https://github.com/PHPOffice/PhpSpreadsheet/pull/3865)
9595
- Use less space when inserting rows and columns. [Issue #3687](https://github.com/PHPOffice/PhpSpreadsheet/issues/3687) [PR #3856](https://github.com/PHPOffice/PhpSpreadsheet/pull/3856)
96+
- Excel inconsistent handling of MIN/MAX/MINA/MAXA. [Issue #3866](https://github.com/PHPOffice/PhpSpreadsheet/issues/3866) [PR #3868](https://github.com/PHPOffice/PhpSpreadsheet/pull/3868)
9697

9798
## 1.29.0 - 2023-06-15
9899

docs/topics/recipes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ At present, the following locale settings are supported:
415415

416416
Language | | Locale Code
417417
---------------------|----------------------|-------------
418+
Bulgarian | български | bg
418419
Czech | Ceština | cs
419420
Danish | Dansk | da
420421
German | Deutsch | de

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4997,7 +4997,12 @@ private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell
49974997
}
49984998
} else {
49994999
$emptyArguments[] = ($arg['type'] === 'Empty Argument');
5000-
$args[] = self::unwrapResult($arg['value']);
5000+
if ($arg['type'] === 'Empty Argument' && in_array($functionName, ['MIN', 'MINA', 'MAX', 'MAXA'], true)) {
5001+
$args[] = $arg['value'] = 0;
5002+
$this->debugLog->writeDebugLog('Empty Argument reevaluated as 0');
5003+
} else {
5004+
$args[] = self::unwrapResult($arg['value']);
5005+
}
50015006
if ($functionName !== 'MKMATRIX') {
50025007
$argArrayVals[] = $this->showValue($arg['value']);
50035008
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
6+
7+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class MissingArgumentsTest extends TestCase
11+
{
12+
/**
13+
* @dataProvider providerMissingArguments
14+
*/
15+
public function testMissingArguments(mixed $expected, string $formula): void
16+
{
17+
$spreadsheet = new Spreadsheet();
18+
$sheet = $spreadsheet->getActiveSheet();
19+
$sheet->getCell('A1')->setValue($formula);
20+
self::assertSame($expected, $sheet->getCell('A1')->getCalculatedValue());
21+
$spreadsheet->disconnectWorksheets();
22+
}
23+
24+
public static function providerMissingArguments(): array
25+
{
26+
return [
27+
'argument missing at end' => [0, '=min(3,2,)'],
28+
'argument missing at beginning' => [0, '=mina(,3,2)'],
29+
'argument missing in middle' => [0, '=min(3,,2)'],
30+
'missing argument is not result' => [-2, '=min(3,-2,)'],
31+
'max with missing argument' => [0, '=max(-3,-2,)'],
32+
'maxa with missing argument' => [0, '=maxa(-3,-2,)'],
33+
'max with null cell' => [-2, '=max(-3,-2,Z1)'],
34+
'min with null cell' => [2, '=min(3,2,Z1)'],
35+
'product ignores null argument' => [6.0, '=product(3,2,)'],
36+
'embedded function' => [5, '=sum(3,2,min(3,2,))'],
37+
'unaffected embedded function' => [8, '=sum(3,2,max(3,2,))'],
38+
];
39+
}
40+
}

0 commit comments

Comments
 (0)