{"record":{"id":"5eaf9e2e1738f4f3","repo":"iOfficeAI/OfficeCLI","slug":"invalid-sparkline-type-spktypestr-valid-valu","errorCode":null,"errorMessage":"Invalid sparkline type: '{spkTypeStr}'. Valid values: line, column, stacked (alias: winloss/win-loss).","messagePattern":"Invalid sparkline type: '(.+?)'\\. Valid values: line, column, stacked \\(alias: winloss/win-loss\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs","lineNumber":1007,"sourceCode":"        // 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\n        var spkGroup = new X14.SparklineGroup();\n        // Only set Type attribute for non-line (line is default in OOXML)\n        if (spkType != X14.SparklineTypeValues.Line)\n            spkGroup.Type = spkType;\n\n        // Series color\n        var spkColor = properties.GetValueOrDefault(\"color\", \"4472C4\");\n        spkGroup.SeriesColor = new X14.SeriesColor { Rgb = ParseHelpers.NormalizeArgbColor(spkColor) };\n\n        // Negative color\n        if (properties.TryGetValue(\"negativecolor\", out var negColor))\n            spkGroup.NegativeColor = new X14.NegativeColor { Rgb = ParseHelpers.NormalizeArgbColor(negColor) };\n\n        // Boolean flags","sourceCodeStart":989,"sourceCodeEnd":1025,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs#L989-L1025","documentation":"Thrown when the sparkline `type=` property (defaulting to `line`) does not map to one of the three OOXML sparkline types. The switch accepts line, column, and stacked (with winloss/win-loss as aliases for stacked). Any other token — e.g. `bar`, `pie`, `area` — hits the default arm and throws. This explicit rejection (vs. silently mapping to line) was added so an invalid type doesn't produce a wrong-shaped sparkline.","triggerScenarios":"Passing `--prop type=bar` (Excel charts have bars; sparklines do not), `--prop type=win_loss` (underscore form not accepted — use win-loss), or `--prop type=area`. Default is line when type is omitted, so this only fires when an explicit bad type is given.","commonSituations":"Confusing sparkline types with chart types; using underscore-separated form (`win_loss`) instead of hyphenated (`win-loss`); locale-specific terms.","solutions":["Use line, column, or stacked (winloss / win-loss alias stacked).","Omit type to get the default line sparkline."],"exampleFix":"// before\nadd ./book.xlsx /Sheet1 sparkline --prop location=F1 --prop dataRange=A1:E1 --prop type=bar\n// after\nadd ./book.xlsx /Sheet1 sparkline --prop location=F1 --prop dataRange=A1:E1 --prop type=column","handlingStrategy":"type-guard","validationCode":"var validSparkType = new[]{\"line\",\"column\",\"stacked\",\"winloss\",\"win-loss\"};\nif (!validSparkType.Contains((sparkType ?? \"line\").ToLowerInvariant()))\n    throw new InvalidOperationException($\"Invalid sparkline type '{sparkType}'\");","typeGuard":"static readonly HashSet<string> SparkTypeTokens = new(StringComparer.OrdinalIgnoreCase)\n    {\"line\",\"column\",\"stacked\",\"winloss\",\"win-loss\"};\nstatic bool IsValidSparklineType(string? v) => v is null || SparkTypeTokens.Contains(v);","tryCatchPattern":"try { handler.AddSparkline(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid sparkline type\"))\n{ /* default to line or reprompt with the 3 types */ }","preventionTips":["Sparkline types are line/column/stacked only — there is no bar/area/pie.","Use the hyphenated `win-loss` form, not `win_loss`."],"tags":["excel","sparkline","enum-value","input-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}