PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

Invalid Operator for Cell Value CF Rule Wizard

Error message

Invalid Operator for Cell Value CF Rule Wizard

What it means

CellValue exposes its comparison operators through __call against a MAGIC_OPERATIONS map containing exactly: equals, notEquals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, between, notBetween (plus the special-cased and). Any other method name throws - the most common case being a typo such as greaterThen, or a method that belongs to a different wizard (contains, today, isBlank) invoked on a CellValue instance.

Source

Thrown at src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php:173

    }

    /**
     * @param mixed[] $arguments
     */
    public function __call(string $methodName, array $arguments): self
    {
        if ($methodName === 'and') {
            if (!isset(self::RANGE_OPERATORS[$this->operator])) {
                throw new Exception('AND Value is only appropriate for range operators');
            }

            $this->operand(1, ...$arguments);

            return $this;
        }

        if (!isset(self::MAGIC_OPERATIONS[$methodName])) {
            throw new Exception('Invalid Operator for Cell Value CF Rule Wizard');
        }

        $this->operator(self::MAGIC_OPERATIONS[$methodName]);
        //$this->operand(0, ...$arguments);
        if (count($arguments) < 2) {
            $this->operand(0, $arguments[0]);
        } else {
            /** @var string */
            $arg1 = $arguments[1];
            $this->operand(0, $arguments[0], $arg1);
        }

        return $this;
    }

    /** @internal */
    public static function compareKeys(): bool
    {

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Use exactly the documented operators: equals, notEquals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, between, notBetween
  2. Check dynamic method names against that list before invoking
  3. Rely on the @method docblock annotations for autocompletion instead of guessing names
  4. Catch PhpSpreadsheetException around dynamic fluent calls

Example fix

// before
$wizard = (new Wizard('A1:E10'))->newRule(Wizard::CELL_VALUE);
$wizard->greaterThen(100);   // typo: throws Invalid Operator

// after
$wizard->greaterThan(100);
Defensive patterns

Strategy: validation

Validate before calling

$allowed = ['equals', 'notEquals', 'greaterThan', 'greaterThanOrEqual',
    'lessThan', 'lessThanOrEqual', 'between', 'notBetween', 'and'];
$method = $config['operator'];
if (!in_array($method, $allowed, true)) {
    throw new InvalidArgumentException('Unknown CellValue operator: ' . $method);
}
$wizard->$method($value);

Try / catch

use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;

try {
    $wizard->greaterThan($value);
} catch (PhpSpreadsheetException $e) {
    throw new InvalidArgumentException('Invalid CellValue operator call', 0, $e);
}

Prevention

When it happens

Trigger: ->greaterThen(5) (typo); guessed names like ->above(5) or ->below(5); pasting operator chains from TextValue or DateValue wizards onto a CellValue rule; dynamic method names from configuration.

Common situations: IDE autocompletion across similar wizard classes; refactoring a rule from one wizard type to another without updating the operator calls; building fluent chains from user input.

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/bf3b7b70751bcd10. Report an issue: GitHub.