iOfficeAI/OfficeCLI · error · System.ArgumentException

cellIs conditional formatting requires 'value' property (e.g

Error message

cellIs conditional formatting requires 'value' property (e.g. value=50).

What it means

Thrown by AddCellIs when none of the accepted property keys supply the primary comparison value. The builder checks 'value', then 'formula', then 'value1'. A cellIs cfRule requires at least one <x:formula> child carrying the comparison operand; without it the rule has nothing to compare each cell against.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs:546

        var opStr = (properties.GetValueOrDefault("operator") ?? "greaterThan").Trim();
        var opVal = opStr.ToLowerInvariant() switch
        {
            "greaterthan" or "gt" or ">" => ConditionalFormattingOperatorValues.GreaterThan,
            "lessthan" or "lt" or "<" => ConditionalFormattingOperatorValues.LessThan,
            "greaterthanorequal" or "gte" or ">=" => ConditionalFormattingOperatorValues.GreaterThanOrEqual,
            "lessthanorequal" or "lte" or "<=" => ConditionalFormattingOperatorValues.LessThanOrEqual,
            "equal" or "eq" or "=" or "==" => ConditionalFormattingOperatorValues.Equal,
            "notequal" or "ne" or "!=" or "<>" => ConditionalFormattingOperatorValues.NotEqual,
            "between" => ConditionalFormattingOperatorValues.Between,
            "notbetween" => ConditionalFormattingOperatorValues.NotBetween,
            _ => throw new ArgumentException(
                $"Unsupported cellIs operator '{opStr}'. Valid: greaterThan, lessThan, greaterThanOrEqual, lessThanOrEqual, equal, notEqual, between, notBetween.")
        };

        var primary = properties.GetValueOrDefault("value")
            ?? properties.GetValueOrDefault("formula")
            ?? properties.GetValueOrDefault("value1")
            ?? throw new ArgumentException("cellIs conditional formatting requires 'value' property (e.g. value=50).");
        var secondary = properties.GetValueOrDefault("value2")
            ?? properties.GetValueOrDefault("formula2")
            ?? properties.GetValueOrDefault("maxvalue");

        if ((opVal == ConditionalFormattingOperatorValues.Between
             || opVal == ConditionalFormattingOperatorValues.NotBetween)
            && secondary == null)
        {
            throw new ArgumentException(
                $"cellIs operator '{opStr}' requires 'value2' property (e.g. value=10 value2=50).");
        }

        // cellIs value/value2 land in <x:formula> (A1-only). Reject R1C1-style
        // refs so the file doesn't silently become one Excel refuses to open.
        ValidateNoR1C1Reference(primary);
        if (secondary != null) ValidateNoR1C1Reference(secondary);

        // Build DifferentialFormat (dxf)

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Supply the comparison literal via 'value' (e.g. value=50).
  2. Aliases 'formula' and 'value1' are also accepted.
  3. The value must be A1-style (R1C1 refs are rejected separately by ValidateNoR1C1Reference).

Example fix

// before: no value
add /Sheet1/A1:A10 cellis operator=greaterThan fill=FF0000
// after
add /Sheet1/A1:A10 cellis operator=greaterThan value=100 fill=FF0000
Defensive patterns

Strategy: validation

Validate before calling

if (!properties.ContainsKey("value") && !properties.ContainsKey("formula") && !properties.ContainsKey("value1"))
    throw new ArgumentException("cellIs requires 'value' (aliases: formula, value1).");

Type guard

static bool HasCellIsValue(IReadOnlyDictionary<string,string> p)
    => p.ContainsKey("value") || p.ContainsKey("formula") || p.ContainsKey("value1");

Try / catch

try { return Add(path, "cellis", pos, props); }
catch (ArgumentException ex) when (ex.Message.Contains("requires 'value'"))
{ /* prompt for value, retry */ throw; }

Prevention

When it happens

Trigger: Calling Add with type=cellis and an operator, but omitting all of value, formula, and value1. Example: add /Sheet1/A1:A10 cellis operator=greaterThan (no value).

Common situations: User expects the value to come from a referenced cell; misspelled key (values= instead of value=); assumed the operator alone is sufficient.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/d01ecf353c55e186. Report an issue: GitHub.