iOfficeAI/OfficeCLI · error · ArgumentException
criteria{colId}.{op} requires a numeric value, got: '{rawVal
Error message
criteria{colId}.{op} requires a numeric value, got: '{rawVal}' What it means
Thrown by AddAutoFilter when a Top-N / Bottom-N filter operator (top, topPercent, bottom, bottomPercent) receives a value that is not parseable as a double using InvariantCulture. Excel's <top10> element requires a numeric Val attribute, so a non-numeric string cannot be serialized correctly. The handler validates up front rather than emitting a bad part.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs:891
customEntries.Add((FilterOperatorValues.LessThanOrEqual, hi));
customFilterAnd = true;
}
else
{
// notBetween = lt lo OR gt hi (Excel default OR)
customEntries.Add((FilterOperatorValues.LessThan, lo));
customEntries.Add((FilterOperatorValues.GreaterThan, hi));
}
break;
}
case "top":
case "toppercent":
case "bottom":
case "bottompercent":
{
if (!double.TryParse(rawVal, System.Globalization.NumberStyles.Any,
System.Globalization.CultureInfo.InvariantCulture, out var topN))
throw new ArgumentException(
$"criteria{colId}.{op} requires a numeric value, got: '{rawVal}'");
filterColumn.Top10 = new Top10
{
Top = op == "top" || op == "toppercent",
Percent = op == "toppercent" || op == "bottompercent",
Val = topN
};
handledDedicated = true;
break;
}
case "blanks":
if (IsTruthy(rawVal))
{
filterColumn.Filters = new Filters { Blank = true };
handledDedicated = true;
}
break;
case "nonblanks":View on GitHub (pinned to 1ced45e900)
Solutions
- Pass a plain numeric value, e.g. criteria2.top=10 or criteria2.toppercent=25.
- For percentages use a dot as the decimal separator: criteria2.toppercent=12.5.
- Ensure the value is non-empty; an empty string fails the double.TryParse.
Example fix
// before --prop criteria2.top=ten // after --prop criteria2.top=10
Defensive patterns
Strategy: validation
Validate before calling
// Validate top/bottom filter values parse as invariant-culture doubles before Add.
static bool TryValidateTopN(string op, string rawVal, out string error)
{
error = null;
if (op is not ("top" or "toppercent" or "bottom" or "bottompercent")) return true;
if (!double.TryParse(rawVal, System.Globalization.NumberStyles.Any,
System.Globalization.CultureInfo.InvariantCulture, out _))
{
error = $"criteria.{op} requires a numeric value, got: '{rawVal}'";
return false;
}
return true;
} Try / catch
try { handler.Add(path, "autofilter", null, props); }
catch (ArgumentException ex) when (ex.Message.Contains("requires a numeric value"))
{ /* surface: top/bottom filters need an invariant-culture number */ } Prevention
- Always format numbers with InvariantCulture (dot decimal) when building criteria values programmatically.
- Reject empty values up front; double.TryParse on empty returns false.
- Document that 'toppercent'/'bottompercent' expect a number (count or percent), not a boolean.
When it happens
Trigger: Calling Add with a property like criteria2.top=ten, criteria2.toppercent=, criteria2.bottom=abc, or criteria2.bottompercent=1,5 (comma-decimal in an invariant-culture parse).
Common situations: Typing the count as a word, leaving the value empty, or passing a locale-formatted number where the comma is the decimal separator (InvariantCulture expects a dot).
Related errors
- Property 'sqref' (or 'range'/'ref') is required for validati
- AutoFilter requires 'range' property (e.g. range=A1:F100)
- Invalid 'range' value: '{afRange}'. Expected a cell range li
- criteria{colId}.{op} requires 'lo,hi', got: '{rawVal}'
- Unsupported criteria operator: '{op}'. Valid: equals, notEqu
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/c2da4d99dbd4ccbf.
Report an issue: GitHub.