1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef; |
6
|
|
|
|
7
|
|
|
class IndirectMissingCellTest extends AllSetupTeardown |
8
|
|
|
{ |
9
|
|
|
public function testIssue4330(): void |
10
|
|
|
{ |
11
|
|
|
$sheet = $this->getSheet(); |
12
|
|
|
$sheet->getCell('A1')->setValue(5); // used in INDIRECT |
13
|
|
|
$sheet->getCell('A2')->setValue(1); |
14
|
|
|
|
15
|
|
|
$sheet->getCell('B1')->setValue(2); |
16
|
|
|
$sheet->getCell('B2')->setValue(4); |
17
|
|
|
$sheet->getCell('B3')->setValue(6); |
18
|
|
|
$sheet->getCell('B4')->setValue(8); |
19
|
|
|
$sheet->getCell('B5')->setValue(10); |
20
|
|
|
$sheet->getCell('B6')->setValue(12); |
21
|
|
|
$sheet->getCell('C1')->setValue('=SUM(B1:INDIRECT("B"&A1))'); |
22
|
|
|
self::assertSame( |
23
|
|
|
30, |
24
|
|
|
$sheet->getCell('C1')->getCalculatedValue(), |
25
|
|
|
'end cell initialized' |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
$sheet->getCell('D1')->setValue(30); |
29
|
|
|
$sheet->getCell('D2')->setValue(60); |
30
|
|
|
$sheet->getCell('D3')->setValue(90); |
31
|
|
|
$sheet->getCell('D4')->setValue(120); |
32
|
|
|
$sheet->getCell('E1')->setValue('=SUM(D1:INDIRECT("D"&A1))'); |
33
|
|
|
self::assertSame( |
34
|
|
|
300, |
35
|
|
|
$sheet->getCell('E1')->getCalculatedValue(), |
36
|
|
|
'end cell not initialized' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
//$sheet->getCell('F1')->setValue(30); |
40
|
|
|
//$sheet->getCell('F2')->setValue(60); |
41
|
|
|
$sheet->getCell('F3')->setValue(90); |
42
|
|
|
$sheet->getCell('F4')->setValue(120); |
43
|
|
|
$sheet->getCell('G1')->setValue( |
44
|
|
|
'=SUM(INDIRECT("F"&A2&":F"&A1))' |
45
|
|
|
); |
46
|
|
|
self::assertSame( |
47
|
|
|
210, |
48
|
|
|
$sheet->getCell('G1')->getCalculatedValue(), |
49
|
|
|
'range with uninitialized cells as INDIRECT argument' |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|