1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Html; |
8
|
|
|
use PhpOffice\PhpSpreadsheetTests\Functional; |
9
|
|
|
|
10
|
|
|
class ExtendForChartsAndImagesTest extends Functional\AbstractFunctional |
11
|
|
|
{ |
12
|
|
|
public function testEmptySheet(): void |
13
|
|
|
{ |
14
|
|
|
$spreadsheet = new Spreadsheet(); |
15
|
|
|
|
16
|
|
|
$this->assertMaxColumnAndMaxRow($spreadsheet, 1, 1); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testSimpleSheet(): void |
20
|
|
|
{ |
21
|
|
|
$spreadsheet = new Spreadsheet(); |
22
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
23
|
|
|
$sheet->setCellValue('B3', 'foo'); |
24
|
|
|
|
25
|
|
|
$this->assertMaxColumnAndMaxRow($spreadsheet, 2, 3); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSheetWithExtraColumnDimensions(): void |
29
|
|
|
{ |
30
|
|
|
$spreadsheet = new Spreadsheet(); |
31
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
32
|
|
|
$sheet->setCellValue('B3', 'foo'); |
33
|
|
|
|
34
|
|
|
// Artificially expend the sheet column count without any real cells |
35
|
|
|
$sheet->getColumnDimension('E'); |
36
|
|
|
|
37
|
|
|
$this->assertMaxColumnAndMaxRow($spreadsheet, 2, 3); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testSheetWithExtraRowDimensions(): void |
41
|
|
|
{ |
42
|
|
|
$spreadsheet = new Spreadsheet(); |
43
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
44
|
|
|
$sheet->setCellValue('B3', 'foo'); |
45
|
|
|
|
46
|
|
|
// Artificially expend the sheet row count without any real cells |
47
|
|
|
$sheet->getRowDimension(5); |
48
|
|
|
|
49
|
|
|
$this->assertMaxColumnAndMaxRow($spreadsheet, 2, 3); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testSheetWithImageBelowData(): void |
53
|
|
|
{ |
54
|
|
|
$spreadsheet = new Spreadsheet(); |
55
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
56
|
|
|
$sheet->setCellValue('B3', 'foo'); |
57
|
|
|
|
58
|
|
|
// Add a drawing to the worksheet |
59
|
|
|
$drawing = new Drawing(); |
60
|
|
|
$drawing->setPath('foo.png', false); |
61
|
|
|
$drawing->setCoordinates('A5'); |
62
|
|
|
$drawing->setWorksheet($sheet); |
63
|
|
|
|
64
|
|
|
$this->assertMaxColumnAndMaxRow($spreadsheet, 2, 5); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testSheetWithImageRightOfData(): void |
68
|
|
|
{ |
69
|
|
|
$spreadsheet = new Spreadsheet(); |
70
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
71
|
|
|
$sheet->setCellValue('B3', 'foo'); |
72
|
|
|
|
73
|
|
|
// Add a drawing to the worksheet |
74
|
|
|
$drawing = new Drawing(); |
75
|
|
|
$drawing->setPath('foo.png', false); |
76
|
|
|
$drawing->setCoordinates('E1'); |
77
|
|
|
$drawing->setWorksheet($sheet); |
78
|
|
|
|
79
|
|
|
$this->assertMaxColumnAndMaxRow($spreadsheet, 5, 3); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function assertMaxColumnAndMaxRow(Spreadsheet $spreadsheet, int $expectedColumnCount, int $expectedRowCount): void |
83
|
|
|
{ |
84
|
|
|
$writer = new Html($spreadsheet); |
85
|
|
|
$html = $writer->generateHtmlAll(); |
86
|
|
|
|
87
|
|
|
$rowCount = substr_count($html, '<tr '); |
88
|
|
|
self::assertSame($expectedRowCount, $rowCount); |
89
|
|
|
|
90
|
|
|
$columnCount = substr_count($html, '<td ') / $rowCount; |
91
|
|
|
|
92
|
|
|
self::assertSame($expectedColumnCount, $columnCount); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|