{"record":{"id":"24651122da540aa9","repo":"PHPOffice/PhpSpreadsheet","slug":"conditional-is-not-a-cell-value-cf-rule-conditiona","errorCode":null,"errorMessage":"Conditional is not a Cell Value CF Rule conditional","messagePattern":"Conditional is not a Cell Value CF Rule conditional","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php","lineNumber":123,"sourceCode":"        $conditional->setStyle($this->getStyle());\n        $conditional->setStopIfTrue($this->getStopIfTrue());\n\n        return $conditional;\n    }\n\n    protected static function unwrapString(string $condition): string\n    {\n        if ((str_starts_with($condition, '\"')) && (str_starts_with(strrev($condition), '\"'))) {\n            $condition = substr($condition, 1, -1);\n        }\n\n        return str_replace('\"\"', '\"', $condition);\n    }\n\n    public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface\n    {\n        if ($conditional->getConditionType() !== Conditional::CONDITION_CELLIS) {\n            throw new Exception('Conditional is not a Cell Value CF Rule conditional');\n        }\n\n        $wizard = new self($cellRange);\n        $wizard->style = $conditional->getStyle();\n        $wizard->stopIfTrue = $conditional->getStopIfTrue();\n\n        $wizard->operator = $conditional->getOperatorType();\n        $conditions = $conditional->getConditions();\n        foreach ($conditions as $index => $condition) {\n            // Best-guess to try and identify if the text is a string literal, a cell reference or a formula?\n            $operandValueType = Wizard::VALUE_TYPE_LITERAL;\n            if (is_string($condition)) {\n                if (Calculation::keyInExcelConstants($condition)) {\n                    $condition = Calculation::getExcelConstants($condition);\n                } elseif (preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF_RELATIVE . '$/i', $condition)) {\n                    $operandValueType = Wizard::VALUE_TYPE_CELL;\n                    $condition = self::reverseAdjustCellRef($condition, $cellRange);\n                } elseif (","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php#L105-L141","documentation":"Wizard\\CellValue::fromConditional() rebuilds a CellValue wizard from an existing Conditional, and only CONDITION_CELLIS conditionals qualify - those are the rules built from comparison operators (equal, greaterThan, between, ...). Text, expression, blanks, errors and date rules use different condition types and are rejected up front.","triggerScenarios":"Passing a Conditional whose getConditionType() is containsText, expression, timePeriod, containsBlanks, containsErrors, etc. to CellValue::fromConditional(); iterating mixed rules with a hard-coded CellValue factory call.","commonSituations":"Generic 'edit existing rule' UIs that pick the wrong wizard class; converting rules loaded from files where the condition type is unknown; copy-pasted conversion pipelines that never check the type.","solutions":["Check $conditional->getConditionType() === Conditional::CONDITION_CELLIS first","Use Wizard::fromConditional() to dispatch to the correct wizard automatically","For formula-style comparisons, use Wizard\\Expression::fromConditional() instead","Guard batch loops with try/catch to skip non-cellIs rules"],"exampleFix":"// before\n$wizard = Wizard\\CellValue::fromConditional($conditional); // throws unless type is cellIs\n\n// after\nuse PhpOffice\\PhpSpreadsheet\\Style\\Conditional;\n\nif ($conditional->getConditionType() === Conditional::CONDITION_CELLIS) {\n    $wizard = Wizard\\CellValue::fromConditional($conditional);\n} else {\n    $wizard = Wizard::fromConditional($conditional); // dispatches on actual type\n}","handlingStrategy":"type-guard","validationCode":"use PhpOffice\\PhpSpreadsheet\\Style\\Conditional;\n\nif ($conditional->getConditionType() === Conditional::CONDITION_CELLIS) {\n    $wizard = Wizard\\CellValue::fromConditional($conditional, $cellRange);\n} else {\n    $wizard = Wizard::fromConditional($conditional, $cellRange);\n}","typeGuard":"function isCellValueConditional(Conditional $conditional): bool\n{\n    return $conditional->getConditionType() === Conditional::CONDITION_CELLIS;\n}","tryCatchPattern":"use PhpOffice\\PhpSpreadsheet\\Exception as PhpSpreadsheetException;\n\ntry {\n    $wizard = Wizard\\CellValue::fromConditional($conditional, $cellRange);\n} catch (PhpSpreadsheetException $e) {\n    $wizard = Wizard::fromConditional($conditional, $cellRange);\n}","preventionTips":["Verify the condition type is cellIs before using the CellValue factory","Use Wizard::fromConditional() when the rule's origin is unknown","Treat formula-based comparisons as EXPRESSION rules","Centralize type dispatch in one place instead of scattering per-class calls"],"tags":["php","phpspreadsheet","conditional-formatting","wizard","cell-value","type-mismatch"],"backgroundTag":"conditional-rule-type-mismatch","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}