1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Settings; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Conditional; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Fill; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; |
10
|
|
|
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; |
11
|
|
|
|
12
|
|
|
class ConditionalTest extends AbstractFunctional |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
private $prevValue; |
18
|
|
|
|
19
|
|
|
protected function setUp(): void |
20
|
|
|
{ |
21
|
|
|
$this->prevValue = Settings::getLibXmlLoaderOptions(); |
22
|
|
|
|
23
|
|
|
// Disable validating XML with the DTD |
24
|
|
|
Settings::setLibXmlLoaderOptions($this->prevValue & ~LIBXML_DTDVALID & ~LIBXML_DTDATTR & ~LIBXML_DTDLOAD); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function tearDown(): void |
28
|
|
|
{ |
29
|
|
|
Settings::setLibXmlLoaderOptions($this->prevValue); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Test check if conditional style with type 'notContainsText' works on xlsx. |
34
|
|
|
*/ |
35
|
|
|
public function testConditionalNotContainsText(): void |
36
|
|
|
{ |
37
|
|
|
$spreadsheet = new Spreadsheet(); |
38
|
|
|
$worksheet = $spreadsheet->getActiveSheet(); |
39
|
|
|
|
40
|
|
|
$condition = new Conditional(); |
41
|
|
|
$condition->setConditionType(Conditional::CONDITION_NOTCONTAINSTEXT); |
42
|
|
|
$condition->setOperatorType(Conditional::OPERATOR_NOTCONTAINS); |
43
|
|
|
$condition->setText('C'); |
44
|
|
|
$condition->getStyle()->applyFromArray([ |
45
|
|
|
'fill' => [ |
46
|
|
|
'color' => ['argb' => 'FFFFC000'], |
47
|
|
|
'fillType' => Fill::FILL_SOLID, |
48
|
|
|
], |
49
|
|
|
]); |
50
|
|
|
$worksheet->setConditionalStyles('A1:A5', [$condition]); |
51
|
|
|
|
52
|
|
|
$writer = new Xlsx($spreadsheet); |
53
|
|
|
$writerWorksheet = new Xlsx\Worksheet($writer); |
54
|
|
|
$data = $writerWorksheet->writeWorksheet($worksheet, []); |
55
|
|
|
$needle = <<<xml |
56
|
|
|
<conditionalFormatting sqref="A1:A5"><cfRule type="notContainsText" dxfId="" priority="1" operator="notContains" text="C"><formula>ISERROR(SEARCH("C",A1:A5))</formula></cfRule></conditionalFormatting> |
57
|
|
|
xml; |
58
|
|
|
self::assertStringContainsString($needle, $data); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|