iOfficeAI/OfficeCLI · error · ArgumentException

criteria{colId}.{op} requires 'lo,hi', got: '{rawVal}'

Error message

criteria{colId}.{op} requires 'lo,hi', got: '{rawVal}'

What it means

Thrown by AddAutoFilter when a 'between' or 'notBetween' filter criteria value does not split into exactly two comma-separated parts. The handler parses 'lo,hi' into a low and high bound to build Excel's customFilters (between = gte lo AND lte hi; notBetween = lt lo OR gt hi), so anything other than exactly one comma is unusable. It fails fast rather than emitting a malformed <customFilters> that Excel would silently drop.

Source

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

                    }
                    case "gt":
                        customEntries.Add((FilterOperatorValues.GreaterThan, rawVal));
                        break;
                    case "gte":
                        customEntries.Add((FilterOperatorValues.GreaterThanOrEqual, rawVal));
                        break;
                    case "lt":
                        customEntries.Add((FilterOperatorValues.LessThan, rawVal));
                        break;
                    case "lte":
                        customEntries.Add((FilterOperatorValues.LessThanOrEqual, rawVal));
                        break;
                    case "between":
                    case "notbetween":
                    {
                        var parts = rawVal.Split(',');
                        if (parts.Length != 2)
                            throw new ArgumentException(
                                $"criteria{colId}.{op} requires 'lo,hi', got: '{rawVal}'");
                        var lo = parts[0].Trim();
                        var hi = parts[1].Trim();
                        if (op == "between")
                        {
                            customEntries.Add((FilterOperatorValues.GreaterThanOrEqual, lo));
                            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":

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Provide exactly two comma-separated values: low first, high second, e.g. criteria0.between=10,100.
  2. If you only have one bound, use gt/gte/lt/lte instead of between.
  3. Confirm the value is not using a comma as a decimal separator; use a dot for decimals.

Example fix

// before
--prop criteria0.between=50
// after
--prop criteria0.between=10,100
Defensive patterns

Strategy: validation

Validate before calling

// Validate a between/notBetween value has exactly two comma-separated bounds before calling Add.
static bool TryValidateBetween(string op, string rawVal, out string error)
{
    error = null;
    if (op is not ("between" or "notbetween")) return true;
    var parts = rawVal.Split(',');
    if (parts.Length != 2 || string.IsNullOrWhiteSpace(parts[0]) || string.IsNullOrWhiteSpace(parts[1]))
    {
        error = $"criteria.{op} requires 'lo,hi', got: '{rawVal}'";
        return false;
    }
    return true;
}

Try / catch

try { handler.Add(path, "autofilter", null, props); }
catch (ArgumentException ex) when (ex.Message.Contains("requires 'lo,hi'"))
{ /* surface to user: between/notBetween need two comma-separated bounds */ }

Prevention

When it happens

Trigger: Calling Add (or `add --type autofilter`) with a property key matching ^criteria(\d+).(between|notBetween)$ whose value has zero commas (e.g. criteria0.between=10), more than one comma (e.g. criteria0.between=10,20,30), or a trailing/leading comma only (e.g. criteria0.notBetween=,5).

Common situations: Users pasting a single bound expecting a one-sided range, locale confusion (comma used as decimal separator so '1,5' intended as 1.5), or copy-pasting a three-value range from a docs example.

Related errors


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