PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Conditional is not a Blanks CF Rule conditional
Error message
Conditional is not a Blanks CF Rule conditional
What it means
Wizard\Blanks::fromConditional() converts an existing Conditional back into a Blanks wizard, but a Blanks wizard can only represent the containsBlanks and notContainsBlanks condition types. Any other condition type is rejected immediately instead of producing a wizard that would silently misrepresent the rule.
Source
Thrown at src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Blanks.php:71
$conditional = new Conditional();
$conditional->setConditionType(
$this->inverse ? Conditional::CONDITION_CONTAINSBLANKS : Conditional::CONDITION_NOTCONTAINSBLANKS
);
$conditional->setConditions([$this->expression]);
$conditional->setStyle($this->getStyle());
$conditional->setStopIfTrue($this->getStopIfTrue());
return $conditional;
}
public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface
{
if (
$conditional->getConditionType() !== Conditional::CONDITION_CONTAINSBLANKS
&& $conditional->getConditionType() !== Conditional::CONDITION_NOTCONTAINSBLANKS
) {
throw new Exception('Conditional is not a Blanks CF Rule conditional');
}
$wizard = new self($cellRange);
$wizard->style = $conditional->getStyle();
$wizard->stopIfTrue = $conditional->getStopIfTrue();
$wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_CONTAINSBLANKS;
return $wizard;
}
/**
* @param mixed[] $arguments
*/
public function __call(string $methodName, array $arguments): self
{
if (!array_key_exists($methodName, self::OPERATORS)) {
throw new Exception('Invalid Operation for Blanks CF Rule Wizard');
}View on GitHub (pinned to 65b080eef4)
Solutions
- Check that getConditionType() is CONDITION_CONTAINSBLANKS or CONDITION_NOTCONTAINSBLANKS before calling
- Use Wizard::fromConditional() for automatic dispatch to the right wizard class
- If the rule is an expression-based blank test, convert it with Wizard\Expression::fromConditional() instead
- Wrap batch conversions in try/catch to skip wrong-type rules
Example fix
// before
$wizard = Wizard\Blanks::fromConditional($conditional); // throws unless containsBlanks/notContainsBlanks
// after
use PhpOffice\PhpSpreadsheet\Style\Conditional;
if (in_array($conditional->getConditionType(),
[Conditional::CONDITION_CONTAINSBLANKS, Conditional::CONDITION_NOTCONTAINSBLANKS], true)) {
$wizard = Wizard\Blanks::fromConditional($conditional);
} else {
$wizard = Wizard::fromConditional($conditional); // correct wizard for the actual type
} Defensive patterns
Strategy: type-guard
Validate before calling
use PhpOffice\PhpSpreadsheet\Style\Conditional;
if (in_array($conditional->getConditionType(),
[Conditional::CONDITION_CONTAINSBLANKS, Conditional::CONDITION_NOTCONTAINSBLANKS], true)) {
$wizard = Wizard\Blanks::fromConditional($conditional, $cellRange);
} else {
$wizard = Wizard::fromConditional($conditional, $cellRange);
} Type guard
function isBlanksConditional(Conditional $conditional): bool
{
return in_array(
$conditional->getConditionType(),
[Conditional::CONDITION_CONTAINSBLANKS, Conditional::CONDITION_NOTCONTAINSBLANKS],
true
);
} Try / catch
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
try {
$wizard = Wizard\Blanks::fromConditional($conditional, $cellRange);
} catch (PhpSpreadsheetException $e) {
$wizard = Wizard::fromConditional($conditional, $cellRange); // dispatch on real type
} Prevention
- Check getConditionType() against the two blanks constants before calling the Blanks factory
- Prefer the generic Wizard::fromConditional() for unknown rule sets
- Recognize expression-based blank tests (LEN(TRIM(...))) as EXPRESSION rules, not blanks rules
- Keep one shared type-dispatch helper instead of per-class fromConditional calls
When it happens
Trigger: Calling Wizard\Blanks::fromConditional() on a Conditional created by a CellValue, TextValue, Expression or DateValue wizard; looping over mixed conditional rules and forcing each one through the Blanks factory.
Common situations: Copy-pasted rule-conversion code that assumes every rule highlights blanks; blank-detection rules that were saved as EXPRESSION rules (LEN(TRIM(A1))=0 formulas) rather than true containsBlanks rules; processing imported files where each rule's type is unknown until runtime.
Related errors
- Invalid Operation for Blanks CF Rule Wizard
- Conditional is not a Cell Value CF Rule conditional
- Conditional is not a Date Value CF Rule conditional
- Conditional is not a Duplicates CF Rule conditional
- Conditional is not an Errors CF Rule conditional
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/ec7fc5e3b7676e70.
Report an issue: GitHub.