mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 08:09:15 +00:00
Incorrect SUMPRODUCT Calculation
Fix #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 #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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user