iOfficeAI/OfficeCLI · error · ArgumentException

Unknown validation type: {dvType}. Use: list, whole, decimal

Error message

Unknown validation type: {dvType}. Use: list, whole, decimal, date, time, textLength, custom

What it means

Thrown by AddValidation when the optional "type" property is present but its lower-cased value is not one of list, whole, decimal, date, time, textlength, custom. These map 1:1 to DataValidationValues; anything else is rejected rather than silently defaulting.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs:542

        var dv = new DataValidation
        {
            SequenceOfReferences = new ListValue<StringValue>(
                dvSqref.Split(' ').Select(s => new StringValue(s)))
        };

        if (properties.TryGetValue("type", out var dvType))
        {
            dv.Type = dvType.ToLowerInvariant() switch
            {
                "list" => DataValidationValues.List,
                "whole" => DataValidationValues.Whole,
                "decimal" => DataValidationValues.Decimal,
                "date" => DataValidationValues.Date,
                "time" => DataValidationValues.Time,
                "textlength" => DataValidationValues.TextLength,
                "custom" => DataValidationValues.Custom,
                _ => throw new ArgumentException($"Unknown validation type: {dvType}. Use: list, whole, decimal, date, time, textLength, custom")
            };
        }

        if (properties.TryGetValue("operator", out var dvOp))
        {
            dv.Operator = dvOp.ToLowerInvariant() switch
            {
                "between" => DataValidationOperatorValues.Between,
                "notbetween" => DataValidationOperatorValues.NotBetween,
                "equal" => DataValidationOperatorValues.Equal,
                "notequal" => DataValidationOperatorValues.NotEqual,
                "greaterthan" => DataValidationOperatorValues.GreaterThan,
                "lessthan" => DataValidationOperatorValues.LessThan,
                "greaterthanorequal" => DataValidationOperatorValues.GreaterThanOrEqual,
                "lessthanorequal" => DataValidationOperatorValues.LessThanOrEqual,
                _ => throw new ArgumentException($"Unknown operator: {dvOp}")
            };
        }

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use one of: list, whole, decimal, date, time, textLength, custom (case-insensitive, textLength is one word).
  2. For whole numbers use "whole"; for fractions use "decimal".
  3. Validate the value against the allowed set before calling.

Example fix

// before
handler.Add("/Sheet1", "validation", null,
    new() { ["sqref"] = "A1:A5", ["type"] = "integer" });
// after
handler.Add("/Sheet1", "validation", null,
    new() { ["sqref"] = "A1:A5", ["type"] = "whole" });
Defensive patterns

Strategy: type-guard

Validate before calling

static readonly HashSet<string> DvTypes = new(StringComparer.OrdinalIgnoreCase)
    { "list", "whole", "decimal", "date", "time", "textlength", "custom" };
if (properties.TryGetValue("type", out var t) && !DvTypes.Contains(t))
    throw new ArgumentOutOfRangeException($"bad validation type '{t}'");

Type guard

static bool IsValidValidationType(string? t) =>
    t is not null && (new[] { "list", "whole", "decimal", "date", "time", "textlength", "custom" })
        .Contains(t, StringComparer.OrdinalIgnoreCase);

Prevention

When it happens

Trigger: Call Add type "validation" with properties["type"] set to a value outside the enumerated set (e.g. "integer", "numeric", "whole number", "Text").

Common situations: Using the Excel-UI label ('Whole number') instead of the token; expecting 'integer' as a synonym for 'whole'; typos; trailing whitespace.

Related errors


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