1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class Issue4248Test extends TestCase |
14
|
|
|
{ |
15
|
|
|
private string $outfile = ''; |
16
|
|
|
|
17
|
|
|
protected function tearDown(): void |
18
|
|
|
{ |
19
|
|
|
if ($this->outfile !== '') { |
20
|
|
|
unlink($this->outfile); |
21
|
|
|
$this->outfile = ''; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testStyles(): void |
26
|
|
|
{ |
27
|
|
|
$file = 'tests/data/Reader/XLSX/issue.4248.xlsx'; |
28
|
|
|
$reader = new XlsxReader(); |
29
|
|
|
$spreadsheet = $reader->load($file); |
30
|
|
|
$writer = new XlsxWriter($spreadsheet); |
31
|
|
|
$this->outfile = File::temporaryFilename(); |
32
|
|
|
$writer->save($this->outfile); |
33
|
|
|
$spreadsheet->disconnectWorksheets(); |
34
|
|
|
|
35
|
|
|
$file = 'zip://'; |
36
|
|
|
$file .= $this->outfile; |
37
|
|
|
$file .= '#xl/styles.xml'; |
38
|
|
|
$data = file_get_contents($file) ?: ''; |
39
|
|
|
$expected = '<fill>' |
40
|
|
|
. '<patternFill patternType="darkDown"/>' |
41
|
|
|
. '</fill>'; |
42
|
|
|
self::assertStringContainsString($expected, $data, 'neither fgColor nor bgColor'); |
43
|
|
|
$expected = '<fill>' |
44
|
|
|
. '<patternFill patternType="darkDown">' |
45
|
|
|
. '<bgColor rgb="FFBDD7EE"/>' |
46
|
|
|
. '</patternFill></fill>'; |
47
|
|
|
self::assertStringContainsString($expected, $data, 'bgColor but no fgColor'); |
48
|
|
|
$expected = '<dxfs count="15">' |
49
|
|
|
. '<dxf>' // dxfId 1 - fill color for Oui |
50
|
|
|
. '<fill>' |
51
|
|
|
. '<patternFill><bgColor rgb="FF00B050"/></patternFill>' |
52
|
|
|
. '</fill>' |
53
|
|
|
. '<border/>' |
54
|
|
|
. '</dxf>' |
55
|
|
|
. '<dxf>' // dxfId 2 - fill color for Non |
56
|
|
|
. '<font><color rgb="FF9C0006"/></font>' |
57
|
|
|
. '<fill>' |
58
|
|
|
. '<patternFill><bgColor rgb="FFFFC7CE"/></patternFill>' |
59
|
|
|
. '</fill>' |
60
|
|
|
. '<border/>' |
61
|
|
|
. '</dxf>'; |
62
|
|
|
self::assertStringContainsString($expected, $data, 'conditional fill styles'); |
63
|
|
|
|
64
|
|
|
$file = 'zip://'; |
65
|
|
|
$file .= $this->outfile; |
66
|
|
|
$file .= '#xl/worksheets/sheet1.xml'; |
67
|
|
|
$data = file_get_contents($file) ?: ''; |
68
|
|
|
$expected = '<conditionalFormatting sqref="C16:C38 E17:H18 I17:J37 D18 J23:J38 E38 I38">' |
69
|
|
|
. '<cfRule type="containsText" dxfId="0" priority="1" operator="containsText" text="Oui">' |
70
|
|
|
. '<formula>NOT(ISERROR(SEARCH("Oui",C16)))</formula>' |
71
|
|
|
. '</cfRule>' |
72
|
|
|
. '</conditionalFormatting>'; |
73
|
|
|
self::assertStringContainsString($expected, $data, 'first condition for D18'); |
74
|
|
|
$expected = '<conditionalFormatting sqref="C16:C38 I17:J37 E17:H18 D18 J23:J38 E38 I38">' |
75
|
|
|
. '<cfRule type="containsText" dxfId="1" priority="2" operator="containsText" text="Non">' |
76
|
|
|
. '<formula>NOT(ISERROR(SEARCH("Non",C16)))</formula>' |
77
|
|
|
. '</cfRule>' |
78
|
|
|
. '</conditionalFormatting>'; |
79
|
|
|
self::assertStringContainsString($expected, $data, 'second condition for D18'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testHtml(): void |
83
|
|
|
{ |
84
|
|
|
$file = 'tests/data/Reader/XLSX/issue.4248.xlsx'; |
85
|
|
|
$reader = new XlsxReader(); |
86
|
|
|
$spreadsheet = $reader->load($file); |
87
|
|
|
$writer = new HtmlWriter($spreadsheet); |
88
|
|
|
|
89
|
|
|
$file = 'zip://'; |
90
|
|
|
$file .= $this->outfile; |
91
|
|
|
$file .= '#xl/styles.xml'; |
92
|
|
|
$data = str_replace(["\r", "\n"], '', $writer->generateHtmlAll()); |
93
|
|
|
$expected = ' <tr class="row17">' // Cell D18 |
94
|
|
|
. ' <td class="column0 style0"> </td>' |
95
|
|
|
. ' <td class="column1 style28 null"></td>' |
96
|
|
|
. ' <td class="column2 style35 s">Eligible </td>' |
97
|
|
|
. ' <td class="column3 style70 f">Non</td>'; |
98
|
|
|
self::assertStringContainsString($expected, $data, 'Cell D18 style'); |
99
|
|
|
$expected = ' td.style70, th.style70 { vertical-align:middle; text-align:center; border-bottom:1px solid #000000 !important; border-top:2px solid #000000 !important; border-left:2px solid #000000 !important; border-right:1px solid #000000 !important; font-weight:bold; color:#000000; font-family:\'Calibri\'; font-size:16pt; background-color:#BDD7EE }'; |
100
|
|
|
self::assertStringContainsString($expected, $data, 'background color'); |
101
|
|
|
|
102
|
|
|
$spreadsheet->disconnectWorksheets(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|