1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
9
|
|
|
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; |
10
|
|
|
|
11
|
|
|
class HtmlArrayTest extends AbstractFunctional |
12
|
|
|
{ |
13
|
|
|
public function testArray(): void |
14
|
|
|
{ |
15
|
|
|
$spreadsheet = new Spreadsheet(); |
16
|
|
|
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); |
17
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
18
|
|
|
$sheet->getCell('A1')->setValue(1); |
19
|
|
|
$sheet->getCell('A2')->setValue(1); |
20
|
|
|
$sheet->getCell('A3')->setValue(3); |
21
|
|
|
$sheet->getCell('B1')->setValue('=UNIQUE(A1:A3)'); |
22
|
|
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Html'); |
23
|
|
|
$sheet = $reloadedSpreadsheet->getActiveSheet(); |
24
|
|
|
self::assertEquals('1', $sheet->getCell('A1')->getValue()); |
25
|
|
|
self::assertEquals('1', $sheet->getCell('A2')->getValue()); |
26
|
|
|
self::assertEquals('3', $sheet->getCell('A3')->getValue()); |
27
|
|
|
self::assertEquals('1', $sheet->getCell('B1')->getValue()); |
28
|
|
|
self::assertEquals('3', $sheet->getCell('B2')->getValue()); |
29
|
|
|
self::assertNull($sheet->getCell('B3')->getValue()); |
30
|
|
|
$spreadsheet->disconnectWorksheets(); |
31
|
|
|
$reloadedSpreadsheet->disconnectWorksheets(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testInlineArrays(): void |
35
|
|
|
{ |
36
|
|
|
$spreadsheet = new Spreadsheet(); |
37
|
|
|
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); |
38
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
39
|
|
|
$sheet->getCell('A1')->setValue('=UNIQUE({1;1;2;1;3;2;4;4;4})'); |
40
|
|
|
$sheet->getCell('D1')->setValue('=UNIQUE({1,1,2,1,3,2,4,4,4},true)'); |
41
|
|
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Csv'); |
42
|
|
|
$sheet = $reloadedSpreadsheet->getActiveSheet(); |
43
|
|
|
$expected = [ |
44
|
|
|
['1', null, null, '1', '2', '3', '4'], |
45
|
|
|
['2', null, null, null, null, null, null], |
46
|
|
|
['3', null, null, null, null, null, null], |
47
|
|
|
['4', null, null, null, null, null, null], |
48
|
|
|
]; |
49
|
|
|
self::assertSame($expected, $sheet->toArray()); |
50
|
|
|
$spreadsheet->disconnectWorksheets(); |
51
|
|
|
$reloadedSpreadsheet->disconnectWorksheets(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|