iOfficeAI/OfficeCLI · error · ArgumentException
series must be added to a chart parent: /SheetName/chart[N]
Error message
series must be added to a chart parent: /SheetName/chart[N]
What it means
Thrown by AddChartSeries when the parentPath does not match the required chart-parent pattern /SheetName/chart[N]. The regex ^/([^/]+)/chart\[(\d+)\]$ requires a leading slash, a sheet name, the literal 'chart[', a 1-based index, and a closing bracket. This guards against appending a series to a non-chart or a malformed path.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs:378
drawingsPart.WorksheetDrawing.Append(anchor);
drawingsPart.WorksheetDrawing.Save();
// Legend is already handled inside BuildChartSpace
var chartIdx = CountExcelCharts(drawingsPart);
return $"/{chartSheetName}/chart[{chartIdx}]";
}
// BUG-002: `add /SheetName/chart[N] --type chart-series` — append a data
// series to an existing chart. Mirrors PowerPointHandler.AddChartSeries
// (R22-1); additionally resolves xlsx cell-range values/categories into
// numRef/strRef + cached snapshot, matching what chart Add emits for
// range-referenced series (CONSISTENCY(chart-series-rangeref-cache)).
private string AddChartSeries(string parentPath, Dictionary<string, string> properties)
{
var m = Regex.Match(parentPath, @"^/([^/]+)/chart\[(\d+)\]$");
if (!m.Success)
throw new ArgumentException(
"series must be added to a chart parent: /SheetName/chart[N]");
var sheetName = m.Groups[1].Value;
var chartIdx = int.Parse(m.Groups[2].Value);
var worksheet = FindWorksheet(sheetName)
?? throw new ArgumentException($"Sheet not found: {sheetName}");
var drawingsPart = worksheet.DrawingsPart
?? throw new ArgumentException("Sheet has no drawings/charts");
var excelCharts = GetExcelCharts(drawingsPart);
if (chartIdx < 1 || chartIdx > excelCharts.Count)
throw new ArgumentException($"Chart {chartIdx} not found (total: {excelCharts.Count})");
var chartInfo = excelCharts[chartIdx - 1];
if (chartInfo.StandardPart == null)
throw new ArgumentException(
$"Chart at {parentPath} is not a standard chart (extended cx charts do not support add series).");
var chartPart = chartInfo.StandardPart;
// Resolve range-reference values/categories against the workbook so
// AddSeries seeds literal data (which becomes the cached snapshot).View on GitHub (pinned to 1ced45e900)
Solutions
- Use the exact format /SheetName/chart[N] where N is the 1-based chart index, e.g. /Sheet1/chart[1].
- First run a list/get to find the correct chart index for the target sheet.
- If the parent is not a chart, remove --type chart-series and use the appropriate element type.
- Ensure the leading slash and square brackets are present.
Example fix
// before add /Sheet1/chart1 --type chart-series --data "S2:5,6,7" // after add /Sheet1/chart[1] --type chart-series --data "S2:5,6,7"
Defensive patterns
Strategy: validation
Validate before calling
// Validate chart-series parent path format before calling AddChartSeries
var pathRegex = new System.Text.RegularExpressions.Regex(@"^/([^/]+)/chart\[(\d+)\]$");
if (!pathRegex.IsMatch(parentPath))
throw new InvalidOperationException(
$"Invalid chart-series parent path '{parentPath}'. Expected /SheetName/chart[N]."); Type guard
static bool IsChartSeriesParentPath(string path) =>
System.Text.RegularExpressions.Regex.IsMatch(path, @"^/([^/]+)/chart\[(\d+)\]$"); Try / catch
try { handler.AddChartSeries(parentPath, properties); }
catch (ArgumentException ex) when (ex.Message.Contains("series must be added to a chart parent"))
{
Console.Error.WriteLine($"{ex.Message} Correct format: /SheetName/chart[N]");
} Prevention
- Always use the exact path format /SheetName/chart[N] for chart-series add.
- Use 1-based chart indices in square brackets.
- Capture and reuse the return path from chart-creation calls to avoid path-construction errors.
- Validate the path with a regex before the add call.
When it happens
Trigger: Calling add with --type chart-series on a parentPath like '/Sheet1', '/Sheet1/chart', '/Sheet1/chart1', '/Sheet1/shape[1]', or 'Sheet1/chart[1]' (missing leading slash). Only the exact pattern /<sheet>/chart[<number>] is accepted.
Common situations: User confuses the chart-series add path with a top-level add path. User writes chart index without brackets (chart1 instead of chart[1]). User targets a shape or picture path by mistake.
Related errors
- dataRange resolved to 0 series columns: a single-column rang
- Chart requires a 'data' property. Use: data="Series1:1,2,3;S
- Sheet not found: {sheetName}
- Sheet has no drawings/charts
- Chart {chartIdx} not found (total: {excelCharts.Count})
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/ad7d06da46b1eb73.
Report an issue: GitHub.