iOfficeAI/OfficeCLI · error · ArgumentException
Invalid sparkline type: '{spkTypeStr}'. Valid values: line,
Error message
Invalid sparkline type: '{spkTypeStr}'. Valid values: line, column, stacked (alias: winloss/win-loss). What it means
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.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs:1007
// semantically dead <xne:sqref> anchor with no warning; validate the
// final sqref like every other cell-ref input.
if (string.IsNullOrWhiteSpace(spkCell)
|| !Regex.IsMatch(spkCell, @"^\$?[A-Za-z]{1,3}\$?\d+(:\$?[A-Za-z]{1,3}\$?\d+)?$"))
throw new ArgumentException(
$"Invalid sparkline 'location': '{spkCell}'. Expected a cell reference like F1 (or a range like F1:F5).");
ParseCellReference(spkCell.Replace("$", "").Split(':')[0]);
// Determine sparkline type
// bt-2: reject invalid types (e.g. "bar") instead of silently mapping
// to Line. Sparkline OOXML has exactly three types: line/column/stacked
// (winloss is an alias for stacked).
var spkTypeStr = properties.GetValueOrDefault("type", "line").ToLowerInvariant();
var spkType = spkTypeStr switch
{
"line" => X14.SparklineTypeValues.Line,
"column" => X14.SparklineTypeValues.Column,
"stacked" or "winloss" or "win-loss" => X14.SparklineTypeValues.Stacked,
_ => throw new ArgumentException(
$"Invalid sparkline type: '{spkTypeStr}'. Valid values: line, column, stacked (alias: winloss/win-loss).")
};
// Build the SparklineGroup
var spkGroup = new X14.SparklineGroup();
// Only set Type attribute for non-line (line is default in OOXML)
if (spkType != X14.SparklineTypeValues.Line)
spkGroup.Type = spkType;
// Series color
var spkColor = properties.GetValueOrDefault("color", "4472C4");
spkGroup.SeriesColor = new X14.SeriesColor { Rgb = ParseHelpers.NormalizeArgbColor(spkColor) };
// Negative color
if (properties.TryGetValue("negativecolor", out var negColor))
spkGroup.NegativeColor = new X14.NegativeColor { Rgb = ParseHelpers.NormalizeArgbColor(negColor) };
// Boolean flagsView on GitHub (pinned to 1ced45e900)
Solutions
- Use line, column, or stacked (winloss / win-loss alias stacked).
- Omit type to get the default line sparkline.
Example fix
// before add ./book.xlsx /Sheet1 sparkline --prop location=F1 --prop dataRange=A1:E1 --prop type=bar // after add ./book.xlsx /Sheet1 sparkline --prop location=F1 --prop dataRange=A1:E1 --prop type=column
Defensive patterns
Strategy: type-guard
Validate before calling
var validSparkType = new[]{"line","column","stacked","winloss","win-loss"};
if (!validSparkType.Contains((sparkType ?? "line").ToLowerInvariant()))
throw new InvalidOperationException($"Invalid sparkline type '{sparkType}'"); Type guard
static readonly HashSet<string> SparkTypeTokens = new(StringComparer.OrdinalIgnoreCase)
{"line","column","stacked","winloss","win-loss"};
static bool IsValidSparklineType(string? v) => v is null || SparkTypeTokens.Contains(v); Try / catch
try { handler.AddSparkline(...); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid sparkline type"))
{ /* default to line or reprompt with the 3 types */ } Prevention
- Sparkline types are line/column/stacked only — there is no bar/area/pie.
- Use the hyphenated `win-loss` form, not `win_loss`.
When it happens
Trigger: 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.
Common situations: Confusing sparkline types with chart types; using underscore-separated form (`win_loss`) instead of hyphenated (`win-loss`); locale-specific terms.
Related errors
- Unknown displayEmptyCellsAs value '{deca}'. Valid: gap, span
- Invalid valign value: '{shpValign}'. Valid: top, center, bot
- Unknown underline value '{shpUnder}'. Valid: single, double,
- Unknown align value '{shpAlign}'. Valid: left, center, right
- Sheet not found: {spkSheetName}
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/5eaf9e2e1738f4f3.
Report an issue: GitHub.