{"record":{"id":"e816879d899d9ba6","repo":"iOfficeAI/OfficeCLI","slug":"invalid-sparkline-location-spkcell-expecte","errorCode":null,"errorMessage":"Invalid sparkline 'location': '{spkCell}'. Expected a cell reference like F1 (or a range like F1:F5).","messagePattern":"Invalid sparkline 'location': '(.+?)'\\. Expected a cell reference like F1 \\(or a range like F1:F5\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs","lineNumber":993,"sourceCode":"            ?? properties.GetValueOrDefault(\"cell\")\n            ?? spkPathTail\n            ?? throw new ArgumentException(\"Sparkline requires 'location' (or 'cell') property (e.g. F1)\");\n        var spkRange = properties.GetValueOrDefault(\"dataRange\")\n            ?? properties.GetValueOrDefault(\"datarange\")\n            ?? properties.GetValueOrDefault(\"range\")\n            ?? properties.GetValueOrDefault(\"data\")\n            ?? throw new ArgumentException(\"Sparkline requires 'dataRange' (or 'range'/'data') property (e.g. A1:E1)\");\n\n        // OOXML xm:sqref is ST_Sqref (bare cell address, no sheet prefix —\n        // sheet is implied by the parent worksheet). Excel silently drops the\n        // entire <extLst> on load if sqref carries a sheet prefix.\n        spkCell = NormalizeSparklineSqref(spkCell, spkSheetName);\n        // A location that is not a real cell reference (\"XYZ\", empty) wrote a\n        // semantically dead <xne:sqref> anchor with no warning; validate the\n        // final sqref like every other cell-ref input.\n        if (string.IsNullOrWhiteSpace(spkCell)\n            || !Regex.IsMatch(spkCell, @\"^\\$?[A-Za-z]{1,3}\\$?\\d+(:\\$?[A-Za-z]{1,3}\\$?\\d+)?$\"))\n            throw new ArgumentException(\n                $\"Invalid sparkline 'location': '{spkCell}'. Expected a cell reference like F1 (or a range like F1:F5).\");\n        ParseCellReference(spkCell.Replace(\"$\", \"\").Split(':')[0]);\n\n        // Determine sparkline type\n        // bt-2: reject invalid types (e.g. \"bar\") instead of silently mapping\n        // to Line. Sparkline OOXML has exactly three types: line/column/stacked\n        // (winloss is an alias for stacked).\n        var spkTypeStr = properties.GetValueOrDefault(\"type\", \"line\").ToLowerInvariant();\n        var spkType = spkTypeStr switch\n        {\n            \"line\" => X14.SparklineTypeValues.Line,\n            \"column\" => X14.SparklineTypeValues.Column,\n            \"stacked\" or \"winloss\" or \"win-loss\" => X14.SparklineTypeValues.Stacked,\n            _ => throw new ArgumentException(\n                $\"Invalid sparkline type: '{spkTypeStr}'. Valid values: line, column, stacked (alias: winloss/win-loss).\")\n        };\n\n        // Build the SparklineGroup","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs#L975-L1011","documentation":"Thrown when the resolved sparkline location, after sheet-prefix stripping (NormalizeSparklineSqref), is empty or does not match the cell-reference regex `^\\$?[A-Za-z]{1,3}\\$?\\d+(:\\$?[A-Za-z]{1,3}\\$?\\d+)?$`. This guard exists because a non-cell location (e.g. `XYZ`, empty, or a label) previously wrote a semantically dead xm:sqref anchor that Excel silently dropped, leaving the sparkline invisible. Unlike 546 (which fires when location is entirely absent), this fires when a location IS supplied but is not a valid cell reference.","triggerScenarios":"Passing `--prop location=Total` (a label, not a cell), `--prop location=` (empty after trim), or a path tail that looks like a cell but isn't (`/Sheet1/ABC`). Also when NormalizeSparklineSqref strips a sheet prefix and leaves nothing valid.","commonSituations":"Pointing the sparkline at a named cell label instead of its address; location derived from a user input field that isn't validated; copy-paste introducing a stray prefix.","solutions":["Supply a concrete cell address for location, e.g. `F1`, or a range `F1:F5` (optional $ signs are tolerated).","Do not include the sheet prefix in location (it is implied by the parent path); NormalizeSparklineSqref strips it but leaving it bare avoids ambiguity."],"exampleFix":"// before\nadd ./book.xlsx /Sheet1 sparkline --prop location=Total --prop dataRange=A1:E1\n// after\nadd ./book.xlsx /Sheet1 sparkline --prop location=F1 --prop dataRange=A1:E1","handlingStrategy":"validation","validationCode":"// Validate the resolved location with the handler's own cell-ref grammar.\nvar cellRe = @\"^\\$?[A-Za-z]{1,3}\\$?\\d+(:\\$?[A-Za-z]{1,3}\\$?\\d+)?$\";\nif (string.IsNullOrWhiteSpace(hostCell) || !Regex.IsMatch(hostCell, cellRe))\n    throw new InvalidOperationException($\"Sparkline location '{hostCell}' is not a cell reference\");","typeGuard":"static bool IsValidSparklineCell(string? s)\n    => !string.IsNullOrWhiteSpace(s)\n    && System.Text.RegularExpressions.Regex.IsMatch(s,\n        @\"^\\$?[A-Za-z]{1,3}\\$?\\d+(:\\$?[A-Za-z]{1,3}\\$?\\d+)?$\");","tryCatchPattern":"try { handler.AddSparkline(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid sparkline 'location'\"))\n{ /* reprompt: need a real cell like F1, not a label */ }","preventionTips":["Never use a label or named token as the sparkline location — only A1-style addresses.","Strip any sheet prefix from location before validating; the host sheet is implied by the path."],"tags":["excel","sparkline","cell-reference","input-validation","ooxml"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}