PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Conditional is not a Duplicates CF Rule conditional
Error message
Conditional is not a Duplicates CF Rule conditional
What it means
Wizard\Duplicates::fromConditional() rebuilds a Duplicates wizard from an existing Conditional, but it can only represent the containsDuplicates (duplicates) and containsUnique (unique) condition types. Any other condition type is rejected immediately with this exception rather than being silently converted.
Source
Thrown at src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Duplicates.php:50
public function getConditional(): Conditional
{
$conditional = new Conditional();
$conditional->setConditionType(
$this->inverse ? Conditional::CONDITION_UNIQUE : Conditional::CONDITION_DUPLICATES
);
$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_DUPLICATES
&& $conditional->getConditionType() !== Conditional::CONDITION_UNIQUE
) {
throw new Exception('Conditional is not a Duplicates CF Rule conditional');
}
$wizard = new self($cellRange);
$wizard->style = $conditional->getStyle();
$wizard->stopIfTrue = $conditional->getStopIfTrue();
$wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_UNIQUE;
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 Duplicates CF Rule Wizard');
}View on GitHub (pinned to 65b080eef4)
Solutions
- Check getConditionType() is CONDITION_DUPLICATES or CONDITION_UNIQUE before calling
- Use Wizard::fromConditional() for automatic dispatch
- Wrap batch conversions in try/catch to skip wrong-type rules
- Log skipped types so unsupported rules are visible during imports
Example fix
// before
$wizard = Wizard\Duplicates::fromConditional($conditional); // throws unless duplicates/unique
// after
use PhpOffice\PhpSpreadsheet\Style\Conditional;
if (in_array($conditional->getConditionType(),
[Conditional::CONDITION_DUPLICATES, Conditional::CONDITION_UNIQUE], true)) {
$wizard = Wizard\Duplicates::fromConditional($conditional);
} else {
$wizard = Wizard::fromConditional($conditional);
} Defensive patterns
Strategy: type-guard
Validate before calling
use PhpOffice\PhpSpreadsheet\Style\Conditional;
if (in_array($conditional->getConditionType(),
[Conditional::CONDITION_DUPLICATES, Conditional::CONDITION_UNIQUE], true)) {
$wizard = Wizard\Duplicates::fromConditional($conditional, $cellRange);
} else {
$wizard = Wizard::fromConditional($conditional, $cellRange);
} Type guard
function isDuplicatesConditional(Conditional $conditional): bool
{
return in_array(
$conditional->getConditionType(),
[Conditional::CONDITION_DUPLICATES, Conditional::CONDITION_UNIQUE],
true
);
} Try / catch
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
try {
$wizard = Wizard\Duplicates::fromConditional($conditional, $cellRange);
} catch (PhpSpreadsheetException $e) {
$wizard = Wizard::fromConditional($conditional, $cellRange);
} Prevention
- Check for CONDITION_DUPLICATES or CONDITION_UNIQUE before calling the Duplicates factory
- Use the generic Wizard::fromConditional() for mixed rule sets
- Counting-based duplicate checks written as formulas are EXPRESSION rules, not duplicates rules
- Skip-and-log unsupported types during rule imports
When it happens
Trigger: Calling Duplicates::fromConditional() on a Conditional whose type is cellIs, containsText, expression, timePeriod, etc.; looping over mixed rules and forcing each through the Duplicates factory.
Common situations: Generic rule-inspection code that assumes all rules are duplicate detectors; round-tripping rule sets where the type of each rule is unknown; copy-pasted conversion snippets.
Related errors
- Conditional is not a Blanks CF Rule conditional
- Conditional is not a Cell Value CF Rule conditional
- Conditional is not a Date Value CF Rule conditional
- Invalid Operation for Duplicates CF Rule Wizard
- Conditional is not an Errors CF Rule conditional
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/19b2d44f52c4b5c3.
Report an issue: GitHub.