{"record":{"id":"65929b39a77b84c6","repo":"iOfficeAI/OfficeCLI","slug":"invalid-sparkline-range-range-row-tm-groups","errorCode":null,"errorMessage":"Invalid sparkline range '{range}': row '{tm.Groups[2].Value}' is outside Excel's grid (1..1048576).","messagePattern":"Invalid sparkline range '(.+?)': 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":613,"sourceCode":"                $\"Invalid sparkline range '{range}'. Expected an A1 range like A1:E1 (optionally sheet-qualified).\");\n        // Grid-bounds check, same family as ValidateSqref: shape-valid B0 or\n        // A99999999 landed verbatim in <xne:f>. Excel tolerates rather than\n        // rejects these, but the sparkline is silently broken — tighten to\n        // the severity every other cell-ref entry point now enforces.\n        foreach (var tok in r.Split(':'))\n        {\n            var tm = System.Text.RegularExpressions.Regex.Match(tok.Trim(),\n                @\"^([A-Za-z]{1,3})?(\\d+)?$\");\n            if (tm.Groups[1].Success && tm.Groups[1].Value.Length > 0)\n            {\n                var colIdx = ColumnNameToIndex(tm.Groups[1].Value.ToUpperInvariant());\n                if (colIdx < 1 || colIdx > 16384)\n                    throw new ArgumentException(\n                        $\"Invalid sparkline range '{range}': column '{tm.Groups[1].Value}' is outside Excel's grid (A..XFD).\");\n            }\n            if (tm.Groups[2].Success && tm.Groups[2].Value.Length > 0\n                && (!long.TryParse(tm.Groups[2].Value, out var rowN) || rowN < 1 || rowN > 1048576))\n                throw new ArgumentException(\n                    $\"Invalid sparkline range '{range}': row '{tm.Groups[2].Value}' is outside Excel's grid (1..1048576).\");\n        }\n    }\n\n    /// <summary>Sanity-check a defined-name body. Full formula validation is\n    /// out of scope, but a sheet-qualified reference must name an existing\n    /// sheet and carry a plausible range/name after the '!' — garbage like\n    /// \"乱码!!!\" written verbatim makes real Excel refuse the file.</summary>\n    internal void ValidateDefinedNameRef(string refText)\n    {\n        // Defined-name bodies are full formulas — validating them properly\n        // is out of scope (functions, unions, cross-part brackets, escaped\n        // apostrophes are all legal). Reject only the empirically fatal\n        // patterns that pass schema validation but make real Excel refuse\n        // the file: doubled/trailing '!' (\"乱码!!!\") and stray '#' outside\n        // the known error literals (\"乱码###\").\n        // Formula-length ceiling (8192) applies to defined-name bodies too.\n        ValidateFormulaLength(refText, \"defined-name ref\");","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs#L595-L631","documentation":"The sparkline range passed the shape check but a row number is outside Excel's grid (must be 1..1048576). As with the column case, Excel tolerates the bad ref but the sparkline is silently broken, so the library rejects up-front.","triggerScenarios":"Passing a sparkline range with a row token like '0', '1048577', or '99999999'. The long.TryParse + bounds check fails.","commonSituations":"Off-by-one row indexing (zero-based leaked into a one-based ref); generated indices never clamped; a row counter that overflowed.","solutions":["Clamp the row to [1,1048576] before building the range string.","Validate row tokens are positive and within bounds upstream.","Use 1-based row numbering consistently."],"exampleFix":"// before\nsheet.SetSparkline(\"F1\", data: \"A0:E0\");\n\n// after\nsheet.SetSparkline(\"F1\", data: \"A1:E1\");","handlingStrategy":"validation","validationCode":"static bool RowWithinGrid(long row) => row >= 1 && row <= 1048576;","typeGuard":null,"tryCatchPattern":"try { sheet.SetSparkline(loc, data); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"1..1048576\")) {\n    // clamp row and retry\n}","preventionTips":["Use 1-based row numbering everywhere; clamp to [1,1048576].","Validate row tokens before assembling the range string."],"tags":["excel","sparkline","cell-reference","grid"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}