#984 add support notContainsText for conditional styles in xlsx
This commit is contained in:
parent
cc5c0205d5
commit
815dabae89
|
|
@ -15,6 +15,7 @@ class Conditional implements IComparable
|
|||
const CONDITION_CONTAINSBLANKS = 'containsBlanks';
|
||||
const CONDITION_NOTCONTAINSBLANKS = 'notContainsBlanks';
|
||||
const CONDITION_DATABAR = 'dataBar';
|
||||
const CONDITION_NOTCONTAINSTEXT = 'notContainsText';
|
||||
|
||||
// Operator types
|
||||
const OPERATOR_NONE = '';
|
||||
|
|
|
|||
|
|
@ -634,15 +634,21 @@ class Worksheet extends WriterPart
|
|||
|
||||
self::writeAttributeif(
|
||||
$objWriter,
|
||||
($conditional->getConditionType() == Conditional::CONDITION_CELLIS || $conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT)
|
||||
&& $conditional->getOperatorType() != Conditional::OPERATOR_NONE,
|
||||
in_array($conditional->getConditionType(), [
|
||||
Conditional::CONDITION_CELLIS,
|
||||
Conditional::CONDITION_CONTAINSTEXT,
|
||||
Conditional::CONDITION_NOTCONTAINSTEXT,
|
||||
]) && $conditional->getOperatorType() != Conditional::OPERATOR_NONE,
|
||||
'operator',
|
||||
$conditional->getOperatorType()
|
||||
);
|
||||
|
||||
self::writeAttributeIf($objWriter, $conditional->getStopIfTrue(), 'stopIfTrue', '1');
|
||||
|
||||
if ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT) {
|
||||
if (in_array($conditional->getConditionType(), [
|
||||
Conditional::CONDITION_CONTAINSTEXT,
|
||||
Conditional::CONDITION_NOTCONTAINSTEXT,
|
||||
])) {
|
||||
self::writeTextCondElements($objWriter, $conditional, $cellCoordinate);
|
||||
} else {
|
||||
self::writeOtherCondElements($objWriter, $conditional, $cellCoordinate);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Settings;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
||||
|
||||
class ConditionalTest extends AbstractFunctional
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $prevValue;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->prevValue = Settings::getLibXmlLoaderOptions();
|
||||
|
||||
// Disable validating XML with the DTD
|
||||
Settings::setLibXmlLoaderOptions($this->prevValue & ~LIBXML_DTDVALID & ~LIBXML_DTDATTR & ~LIBXML_DTDLOAD);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Settings::setLibXmlLoaderOptions($this->prevValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test check if conditional style with type 'notContainsText' works on xlsx
|
||||
*/
|
||||
public function testConditionalNotContainsText(): void
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$condition = new Conditional();
|
||||
$condition->setConditionType(Conditional::CONDITION_NOTCONTAINSTEXT);
|
||||
$condition->setOperatorType(Conditional::OPERATOR_NOTCONTAINS);
|
||||
$condition->setText("C");
|
||||
$condition->getStyle()->applyFromArray([
|
||||
'fill' => [
|
||||
'color' => ['argb' => 'FFFFC000'],
|
||||
'fillType' => Fill::FILL_SOLID,
|
||||
],
|
||||
]);
|
||||
$worksheet->setConditionalStyles('A1:A5', [$condition]);
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$writerWorksheet = new Xlsx\Worksheet($writer);
|
||||
$data = $writerWorksheet->writeWorksheet($worksheet, []);
|
||||
$needle = <<<xml
|
||||
<conditionalFormatting sqref="A1:A5"><cfRule type="notContainsText" dxfId="" priority="1" operator="notContains" text="C"><formula>ISERROR(SEARCH("C",A1:A5))</formula></cfRule></conditionalFormatting>
|
||||
xml;
|
||||
$this->assertStringContainsString($needle, $data);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue