forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PHPOffice#3909. SUMPRODUCT is mishandling multi-row ranges. In Calculation/Calculation, `checkMatrixOperands` will often resize its operands. When it does so, it needs to recalculate the dimensions of each. This fixes the reported problem. Likely cause was PR PHPOffice#3260. That ticket noted the poor coverage of the code being replaced. Tests of the problem in this ticket were absent and are now added. Despite this, I note that `resizeMatricesShrink` is virtually uncovered, and `resizeMatricesExpand` has substantial gaps in its coverage. I have covered some, but not all, of the Expand gaps. I am struggling to come up with examples to fill its remaining gaps and those for Shrink. However, I will merge this fix in about a week even if I don't succeed.
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProduct2Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; | ||
|
||
class SumProduct2Test extends AllSetupTeardown | ||
{ | ||
public function testSUMPRODUCT(): void | ||
{ | ||
$file = 'tests/data/Reader/XLSX/issue.3909b.xlsx'; | ||
$reader = new XlsxReader(); | ||
$spreadsheet = $reader->load($file); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertSame('=SUMPRODUCT(((calNames=I3)*(calTiers=$K$2))*calHours)', $sheet->getCell('K3')->getValue()); | ||
self::assertSame(40, $sheet->getCell('K3')->getCalculatedValue()); | ||
self::assertSame(4, $sheet->getCell('L3')->getCalculatedValue()); | ||
self::assertSame(40, $sheet->getCell('M3')->getCalculatedValue()); | ||
self::assertSame(4, $sheet->getCell('N3')->getCalculatedValue()); | ||
self::assertSame(40, $sheet->getCell('K4')->getCalculatedValue()); | ||
self::assertSame(0, $sheet->getCell('L4')->getCalculatedValue()); | ||
self::assertSame(40, $sheet->getCell('M4')->getCalculatedValue()); | ||
self::assertSame(0, $sheet->getCell('N4')->getCalculatedValue()); | ||
self::assertSame(24, $sheet->getCell('K5')->getCalculatedValue()); | ||
self::assertSame(0, $sheet->getCell('L5')->getCalculatedValue()); | ||
self::assertSame(24, $sheet->getCell('M5')->getCalculatedValue()); | ||
self::assertSame(0, $sheet->getCell('N5')->getCalculatedValue()); | ||
self::assertSame('=SUMPRODUCT(calHours*((calNames=I3)*(calTiers=$K$2)))', $sheet->getCell('I14')->getValue()); | ||
self::assertSame(40, $sheet->getCell('I14')->getCalculatedValue()); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
Binary file not shown.