Skip to content
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

Negative matching of text in conditional formatting #984

Closed
stollr opened this issue May 14, 2019 · 2 comments
Closed

Negative matching of text in conditional formatting #984

stollr opened this issue May 14, 2019 · 2 comments

Comments

@stollr
Copy link

stollr commented May 14, 2019

This is:

- [ ] a bug report
- [x] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

I want some styling to be applied if a cell does NOT contain a specified string.

What is the current behavior?

Currently it is not supported.

What are the steps to reproduce?

<?php
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\Color;

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$conditional = new Conditional();
$conditional->setConditionType(Conditional::CONDITION_CONTAINSTEXT); // == 'containsText'
$conditional->setOperatorType(Conditional::OPERATOR_NOTCONTAINS); // == 'notContains'
$conditional->setText('published');
$conditional->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED);
$conditional->getStyle()->getFont()->setBold(true);

$sheet = $spreadsheet->getActiveSheet();
$cell = $sheet->getCellByColumnAndRow(1, 1);
$cell->setValue('open');
$cell->getStyle()->setConditionalStyles([$this->getConditionalColorForStatus()]);

Which versions of PhpSpreadsheet and PHP are affected?

All.

Explanation

In the above code example I want to style the text in red and bold if the cell does NOT contain the text "published". But this is not possible. At least if you generate an XSLX file.

The OOXML requires the conditional formatting for this case to be defined like this:

	<conditionalFormatting sqref="A1:A1">
		<cfRule type="notContainsText" dxfId="0" priority="3" operator="notContains" text="published">
			<formula>ISERROR(SEARCH("published",A1))</formula>
		</cfRule>
	</conditionalFormatting>

But there is no condition type available to get notContainsText. So this has to be added.

@stale
Copy link

stale bot commented Jul 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Jul 13, 2019
@stale stale bot closed this as completed Jul 20, 2019
oleibman added a commit that referenced this issue May 11, 2021
#984 Add support notContainsText for conditional styles in xlsx
@oleibman
Copy link
Collaborator

oleibman commented Jul 3, 2024

Fixed by PR #2049 in May 2021.

@oleibman oleibman removed the stale label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants