-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#984 Add support notContainsText for conditional styles in xlsx #2049
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
815daba
#984 add support notContainsText for conditional styles in xlsx
xandros15 0b02155
#984 update changelog
xandros15 759c192
#984 fix phpcs warnings
xandros15 a757692
#984 add support notContainsText for conditional styles in xlsx reader
xandros15 2b72c7e
#984 fix Scrutinizer warnings
xandros15 d0f76fd
#984 change to force typing in condition
xandros15 bb11378
#984 fix php-cs-fixer warnings
xandros15 d5492ac
Merge branch 'master' into #984
oleibman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
use PhpOffice\PhpSpreadsheet\Style\Conditional; | ||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; | ||
|
||
class ConditionalTest extends AbstractFunctional | ||
{ | ||
|
||
/** | ||
* Test check if conditional style with type 'notContainsText' works on xlsx | ||
*/ | ||
public function testConditionalNotContainsText(): void | ||
{ | ||
$filename = 'tests/data/Reader/XLSX/conditionalFormatting3Test.xlsx'; | ||
$reader = IOFactory::createReader('Xlsx'); | ||
$spreadsheet = $reader->load($filename); | ||
$worksheet = $spreadsheet->getActiveSheet(); | ||
$styles = $worksheet->getConditionalStyles('A1:A5'); | ||
|
||
$this->assertCount(1, $styles); | ||
|
||
/** @var $notContainsTextStyle Conditional */ | ||
$notContainsTextStyle = $styles[0]; | ||
$this->assertEquals('A', $notContainsTextStyle->getText()); | ||
$this->assertEquals(Conditional::CONDITION_NOTCONTAINSTEXT, $notContainsTextStyle->getConditionType()); | ||
$this->assertEquals(Conditional::OPERATOR_NOTCONTAINS, $notContainsTextStyle->getOperatorType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
===
and!==
where possible.