{"record":{"id":"b7ee91fe06fa1359","repo":"iOfficeAI/OfficeCLI","slug":"invalid-field-value-column-cm-groups-1-v","errorCode":null,"errorMessage":"Invalid {field} '{value}': column '{cm.Groups[1].Value}' is outside Excel's grid (A..XFD).","messagePattern":"Invalid (.+?) '(.+?)': column '(.+?)' is outside Excel's grid \\(A\\.\\.XFD\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs","lineNumber":62,"sourceCode":"        if (!ok)\n            throw new ArgumentException(\n                $\"Invalid {field} '{value}': expected an A1 reference (e.g. 'A1', 'A1:D10', 'A:A', '1:3', 'A1 B2:C5').\");\n        // Shape-valid tokens can still point outside Excel's grid: sqref=\"A0\"\n        // passed here, saved fine, and real Excel refused the whole file\n        // (0x800A03EC) — the same out-of-grid family the drawing-anchor parser\n        // rejects. Bounds-check every cell/row/column component.\n        foreach (var tok in trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries))\n        {\n            foreach (System.Text.RegularExpressions.Match cm in\n                System.Text.RegularExpressions.Regex.Matches(tok, @\"\\$?([A-Z]+)?\\$?([0-9]+)?\",\n                    System.Text.RegularExpressions.RegexOptions.IgnoreCase))\n            {\n                if (cm.Length == 0) continue;\n                if (cm.Groups[1].Success && cm.Groups[1].Value.Length > 0)\n                {\n                    var colIdx = ColumnNameToIndex(cm.Groups[1].Value.ToUpperInvariant());\n                    if (colIdx < 1 || colIdx > 16384)\n                        throw new ArgumentException(\n                            $\"Invalid {field} '{value}': column '{cm.Groups[1].Value}' is outside Excel's grid (A..XFD).\");\n                }\n                if (cm.Groups[2].Success && cm.Groups[2].Value.Length > 0)\n                {\n                    if (!long.TryParse(cm.Groups[2].Value, out var rowNum) || rowNum < 1 || rowNum > 1048576)\n                        throw new ArgumentException(\n                            $\"Invalid {field} '{value}': row '{cm.Groups[2].Value}' is outside Excel's grid (1..1048576).\");\n                }\n            }\n        }\n        // Canonicalize inverted tokens (F5:D3 → D3:F5, per axis) — merge\n        // rejects them and table normalizes them, but CF/DV wrote them\n        // verbatim, leaving a non-canonical sqref whose behavior in real\n        // Excel is undefined. Same convention as the drawing-anchor and\n        // table-range normalization.\n        var normTokens = trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries)\n            .Select(tok =>\n            {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"Generating ranges programmatically with an off-by-one column counter; user input with very long column letters; copying column names without bounds awareness.","solutions":["Clamp column indices to 1..16384 (A..XFD) when generating.","Convert numeric column indices to names with a bounds-checked helper.","Validate with the validationCode before sending."],"exampleFix":"// before\nstring sqref = $\"{ColumnName(16385)}1\"; // XFE1 — out of grid\n// after\nint col = Math.Clamp(col, 1, 16384);\nstring sqref = $\"{ColumnName(col)}1\";","handlingStrategy":"validation","validationCode":"static bool ColumnInGrid(string letters)\n{\n    int idx = ColumnNameToIndex(letters.ToUpperInvariant());\n    return idx >= 1 && idx <= 16384;\n}","typeGuard":"null","tryCatchPattern":"try { ValidateSqref(value, field); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"column\") && ex.Message.Contains(\"outside Excel's grid\"))\n{ /* clamp the offending column to XFD and retry */ }","preventionTips":["Excel's column ceiling is XFD (16384); row ceiling is 1048576.","Bounds-check generated column names before use.","An A1 token can be shape-valid but still out of grid — always check both."],"tags":["excel","conditional-formatting","data-validation","grid-bounds"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}