{"record":{"id":"873955817c8240c9","repo":"iOfficeAI/OfficeCLI","slug":"invalid-field-value-row-cm-groups-2-valu","errorCode":null,"errorMessage":"Invalid {field} '{value}': row '{cm.Groups[2].Value}' is outside Excel's grid (1..1048576).","messagePattern":"Invalid (.+?) '(.+?)': row '(.+?)' is outside Excel's grid \\(1\\.\\.1048576\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs","lineNumber":68,"sourceCode":"        // 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            {\n                var cm = System.Text.RegularExpressions.Regex.Match(tok,\n                    @\"^(\\$?)([A-Z]+)(\\$?)([0-9]+):(\\$?)([A-Z]+)(\\$?)([0-9]+)$\",\n                    System.Text.RegularExpressions.RegexOptions.IgnoreCase);\n                if (cm.Success)\n                {\n                    var c1 = ColumnNameToIndex(cm.Groups[2].Value.ToUpperInvariant());","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs#L50-L86","documentation":"Thrown by ValidateSqref when a shape-valid token has a row component outside Excel's grid (must be 1..1048576). Real Excel refuses files with out-of-grid sqref (0x800A03EC), so the library bounds-checks every row component after the shape check.","triggerScenarios":"Calling a CF/DV API with sqref='A1048577' (row past the ceiling), sqref='A0' (zero is invalid), sqref='A9999999', or any token with a row number outside 1..1048576.","commonSituations":"Generating ranges programmatically with an unbounded row counter; user input with very large numbers; off-by-one from a loop that includes the ceiling+1.","solutions":["Clamp row numbers to 1..1048576 when generating.","Reject row 0 explicitly — rows are 1-based.","Validate with the validationCode before sending."],"exampleFix":"// before\nstring sqref = $\"A{row}\"; // row could be 0 or > 1048576\n// after\nlong r = Math.Clamp(row, 1, 1048576);\nstring sqref = $\"A{r}\";","handlingStrategy":"validation","validationCode":"static bool RowInGrid(string digits)\n    => long.TryParse(digits, out long r) && r >= 1 && r <= 1048576;","typeGuard":"null","tryCatchPattern":"try { ValidateSqref(value, field); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"row\") && ex.Message.Contains(\"outside Excel's grid\"))\n{ /* clamp the offending row to 1..1048576 and retry */ }","preventionTips":["Rows are 1-based; 0 is invalid. Row ceiling is 1048576.","Bounds-check generated row numbers before use.","Excel silently persists out-of-grid refs but refuses to open the file."],"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"}