SUBTOTAL within a SUBTOAL range should be ignored
This commit is contained in:
parent
04b4e74ec7
commit
36afa01d33
|
@ -1088,7 +1088,7 @@ class MathTrig
|
|||
list(, $row, $column) = explode('.', $index);
|
||||
if ($cellReference->getWorksheet()->cellExists($column . $row)) {
|
||||
//take this cell out if it contains the SUBTOTAL formula
|
||||
return strpos(strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()), '=SUBTOTAL(') === false;
|
||||
return !preg_match('/=.*\b(SUBTOTAL)\s*\(/', strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
|
|
@ -547,11 +547,11 @@ class MathTrigTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUBTOTALHIDDEN
|
||||
* @dataProvider providerHiddenSUBTOTAL
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testSUBTOTALHIDDEN($expectedResult, ...$args)
|
||||
public function testHiddenSUBTOTAL($expectedResult, ...$args)
|
||||
{
|
||||
$generator = \PhpOffice\PhpSpreadsheetTests\Calculation\MathTrigTest::rowVisibility();
|
||||
$rowDimension = $this->getMockBuilder(RowDimension::class)
|
||||
|
@ -596,8 +596,47 @@ class MathTrigTest extends TestCase
|
|||
self::assertEquals($expectedResult, $result, null, 1E-12);
|
||||
}
|
||||
|
||||
public function providerSUBTOTALHIDDEN()
|
||||
public function providerHiddenSUBTOTAL()
|
||||
{
|
||||
return require 'data/Calculation/MathTrig/SUBTOTALHIDDEN.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerNestedSUBTOTAL
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testNestedSUBTOTAL($expectedResult, ...$args)
|
||||
{
|
||||
$cell = $this->getMockBuilder(Cell::class)
|
||||
->setMethods(['getValue'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$cell->method('getValue')
|
||||
->willReturn(null);
|
||||
$worksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->setMethods(['cellExists', 'getCell'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$worksheet->method('cellExists')
|
||||
->willReturn(true);
|
||||
$worksheet->method('getCell')
|
||||
->willReturn($cell);
|
||||
$cellReference = $this->getMockBuilder(Cell::class)
|
||||
->setMethods(['getWorksheet'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$cellReference->method('getWorksheet')
|
||||
->willReturn($worksheet);
|
||||
|
||||
array_push($args, $cellReference);
|
||||
$result = MathTrig::SUBTOTAL(...$args);
|
||||
self::assertEquals($expectedResult, $result, null, 1E-12);
|
||||
}
|
||||
|
||||
public function providerNestedSUBTOTAL()
|
||||
{
|
||||
return require 'data/Calculation/MathTrig/SUBTOTALNESTED.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
$baseTestData = [
|
||||
1 => ['A' => 1],
|
||||
2 => ['A' => 1],
|
||||
3 => ['A' => '=SUBTOTAL(1, A1:A2)'],
|
||||
4 => ['A' => '=ROMAN(SUBTOTAL(1, A1:A2))']
|
||||
];
|
||||
|
||||
return [
|
||||
[
|
||||
2,
|
||||
2,
|
||||
$baseTestData,
|
||||
],
|
||||
];
|
Loading…
Reference in New Issue