iOfficeAI/OfficeCLI · error · ArgumentException

Invalid {field} '{value}': column '{cm.Groups[1].Value}' is

Error message

Invalid {field} '{value}': column '{cm.Groups[1].Value}' is outside Excel's grid (A..XFD).

What it means

Thrown by ValidateSqref when a shape-valid token has a column component outside Excel's grid (must be A..XFD, i.e. column index 1..16384). Real Excel refuses files with out-of-grid sqref (0x800A03EC), so the library bounds-checks every column component after the shape check.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs:62

        if (!ok)
            throw new ArgumentException(
                $"Invalid {field} '{value}': expected an A1 reference (e.g. 'A1', 'A1:D10', 'A:A', '1:3', 'A1 B2:C5').");
        // Shape-valid tokens can still point outside Excel's grid: sqref="A0"
        // passed here, saved fine, and real Excel refused the whole file
        // (0x800A03EC) — the same out-of-grid family the drawing-anchor parser
        // rejects. Bounds-check every cell/row/column component.
        foreach (var tok in trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries))
        {
            foreach (System.Text.RegularExpressions.Match cm in
                System.Text.RegularExpressions.Regex.Matches(tok, @"\$?([A-Z]+)?\$?([0-9]+)?",
                    System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                if (cm.Length == 0) continue;
                if (cm.Groups[1].Success && cm.Groups[1].Value.Length > 0)
                {
                    var colIdx = ColumnNameToIndex(cm.Groups[1].Value.ToUpperInvariant());
                    if (colIdx < 1 || colIdx > 16384)
                        throw new ArgumentException(
                            $"Invalid {field} '{value}': column '{cm.Groups[1].Value}' is outside Excel's grid (A..XFD).");
                }
                if (cm.Groups[2].Success && cm.Groups[2].Value.Length > 0)
                {
                    if (!long.TryParse(cm.Groups[2].Value, out var rowNum) || rowNum < 1 || rowNum > 1048576)
                        throw new ArgumentException(
                            $"Invalid {field} '{value}': row '{cm.Groups[2].Value}' is outside Excel's grid (1..1048576).");
                }
            }
        }
        // Canonicalize inverted tokens (F5:D3 → D3:F5, per axis) — merge
        // rejects them and table normalizes them, but CF/DV wrote them
        // verbatim, leaving a non-canonical sqref whose behavior in real
        // Excel is undefined. Same convention as the drawing-anchor and
        // table-range normalization.
        var normTokens = trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries)
            .Select(tok =>
            {

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Clamp column indices to 1..16384 (A..XFD) when generating.
  2. Convert numeric column indices to names with a bounds-checked helper.
  3. Validate with the validationCode before sending.

Example fix

// before
string sqref = $"{ColumnName(16385)}1"; // XFE1 — out of grid
// after
int col = Math.Clamp(col, 1, 16384);
string sqref = $"{ColumnName(col)}1";
Defensive patterns

Strategy: validation

Validate before calling

static bool ColumnInGrid(string letters)
{
    int idx = ColumnNameToIndex(letters.ToUpperInvariant());
    return idx >= 1 && idx <= 16384;
}

Type guard

null

Try / catch

try { ValidateSqref(value, field); }
catch (ArgumentException ex) when (ex.Message.Contains("column") && ex.Message.Contains("outside Excel's grid"))
{ /* clamp the offending column to XFD and retry */ }

Prevention

When it happens

Trigger: Calling a CF/DV API with sqref='XFE1' (column 16385), sqref='AAZ1' (if beyond XFD), sqref='ZZZZ1', or any token whose letters exceed the XFD ceiling. Column-only tokens like 'XFE:XFE' also trigger.

Common situations: Generating ranges programmatically with an off-by-one column counter; user input with very long column letters; copying column names without bounds awareness.

Related errors


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