{"record":{"id":"f44f656daeca74be","repo":"iOfficeAI/OfficeCLI","slug":"invalid-sparkline-range-range-column-tm-gro","errorCode":null,"errorMessage":"Invalid sparkline range '{range}': column '{tm.Groups[1].Value}' is outside Excel's grid (A..XFD).","messagePattern":"Invalid sparkline range '(.+?)': 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":608,"sourceCode":"        r = r.Replace(\"$\", \"\");\n        var ok = r.Length > 0 && r.Split(':').All(tok =>\n            System.Text.RegularExpressions.Regex.IsMatch(tok.Trim(), @\"^([A-Za-z]{1,3}\\d+|[A-Za-z]{1,3}|\\d+)$\"));\n        if (!ok)\n            throw new ArgumentException(\n                $\"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","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs#L590-L626","documentation":"The sparkline range passed the shape check but a column letter resolves to an index outside Excel's grid (must be 1..16384, i.e. A..XFD). Excel tolerates rather than rejects such refs in <xne:f>, but the sparkline is silently broken, so the library tightens to the same severity other cell-ref entry points enforce.","triggerScenarios":"Passing a sparkline range with a column like 'ZZZ' (18278), 'XFE' (16385), or any 3-letter combo past XFD. ColumnNameToIndex returns > 16384 (or < 1).","commonSituations":"Generated column refs from an unbounded counter; copy-paste from a tool with a wider grid; arithmetic that overflowed into a 4th column letter.","solutions":["Cap the column index to [1,16384] before building the range string.","Use IndexToColumnName to construct valid column letters.","Switch from per-column sparkline data to a row-bounded range if you only need a slice."],"exampleFix":"// before\nsheet.SetSparkline(\"F1\", data: \"XFE1:ZZZ1\");\n\n// after\nsheet.SetSparkline(\"F1\", data: \"A1:XFD1\");","handlingStrategy":"validation","validationCode":"static bool ColumnWithinGrid(string colLetters) {\n    int idx = 0;\n    foreach (var ch in colLetters.ToUpperInvariant()) idx = idx * 26 + (ch - 'A' + 1);\n    return idx >= 1 && idx <= 16384;\n}","typeGuard":null,"tryCatchPattern":"try { sheet.SetSparkline(loc, data); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"outside Excel's grid\")) {\n    // clamp column to XFD and retry\n}","preventionTips":["Cap generated column indices to 16384 before formatting letters.","Use IndexToColumnName so out-of-range indices surface as a clear upstream error."],"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"}