iOfficeAI/OfficeCLI · error · ArgumentException
No charts found in sheet
Error message
No charts found in sheet
What it means
Thrown for /Sheet/chart[N]/axis[@role=R] when the sheet has no DrawingsPart at all — i.e. no charts or drawings. The axis sub-path requires at least one chart to exist, so with zero charts the lookup is rejected up front rather than producing a confusing index error. Distinct from the index-out-of-range case (765) which fires when charts exist but N is too large.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Query.cs:673
{
var af = GetSheet(worksheet).GetFirstChild<AutoFilter>();
var afNode = new DocumentNode { Path = path, Type = "autofilter" };
if (af?.Reference?.Value != null) afNode.Format["range"] = af.Reference.Value;
if (af != null) PopulateAutoFilterCriteria(af, afNode);
return afNode;
}
// Chart axis-by-role sub-path: /Sheet1/chart[N]/axis[@role=ROLE].
// Per schemas/help/pptx/chart-axis.json (shared contract).
var chartAxisGetMatch = Regex.Match(cellRef,
@"^chart\[(\d+)\]/axis\[@role=([a-zA-Z0-9_]+)\]$");
if (chartAxisGetMatch.Success)
{
var caChartIdx = int.Parse(chartAxisGetMatch.Groups[1].Value);
var caRole = chartAxisGetMatch.Groups[2].Value;
var caDrawingsPart = worksheet.DrawingsPart;
if (caDrawingsPart == null)
throw new ArgumentException($"No charts found in sheet");
var caAllCharts = GetExcelCharts(caDrawingsPart);
if (caChartIdx < 1 || caChartIdx > caAllCharts.Count)
throw new ArgumentException($"Chart index {caChartIdx} out of range (1-{caAllCharts.Count})");
var caChartInfo = caAllCharts[caChartIdx - 1];
if (caChartInfo.IsExtended || caChartInfo.StandardPart?.ChartSpace == null)
throw new ArgumentException($"Axis not available on chart {caChartIdx}: extended charts not supported.");
var axisNode = ChartHelper.BuildAxisNode(caChartInfo.StandardPart.ChartSpace, caRole, path);
if (axisNode == null)
throw new ArgumentException($"Axis with role '{caRole}' not found on chart {caChartIdx}.");
return axisNode;
}
// Chart path: /Sheet1/chart[N] or /Sheet1/chart[N]/series[K]
var chartMatch = Regex.Match(cellRef, @"^chart\[(\d+)\](?:/series\[(\d+)\])?$");
if (chartMatch.Success)
{
var chartIdx = int.Parse(chartMatch.Groups[1].Value);
var drawingsPart = worksheet.DrawingsPart;View on GitHub (pinned to 1ced45e900)
Solutions
- Verify the sheet has charts before requesting an axis (enumerate the chart list first).
- Point the axis query at a sheet known to contain charts.
- Catch ArgumentException and treat 'No charts found in sheet' as an empty result.
Example fix
// before
var axis = handler.Get("/Sheet1/chart[1]/axis[@role=primary]"); // throws: no charts
// after
try { var axis = handler.Get("/Sheet1/chart[1]/axis[@role=primary]"); }
catch (ArgumentException ex) when (ex.Message.Contains("No charts")) { /* no charts on sheet */ } Defensive patterns
Strategy: try-catch
Try / catch
try { return handler.Get("/Sheet1/chart[1]/axis[@role=primary]"); }
catch (ArgumentException ex) when (ex.Message.Contains("No charts")) { /* sheet has no charts */ return null; } Prevention
- Verify a sheet has charts before issuing an axis sub-path.
- Point axis queries at sheets known to contain charts.
- Treat 'No charts found' as an empty result, not a fatal error.
When it happens
Trigger: handler.Get("/Sheet1/chart[1]/axis[@role=primary]") on a data-only sheet that contains no charts. Running an axis query against the wrong sheet.
Common situations: Agent/template assumes every sheet has charts. Sheet whose charts were deleted but the path wasn't updated. Querying a raw-data sheet for chart structure.
Related errors
- Chart index {caChartIdx} out of range (1-{caAllCharts.Count}
- Axis with role '{caRole}' not found on chart {caChartIdx}.
- Axis not available on chart {caChartIdx}: extended charts no
- Chart index {chartIdx} out of range (1-{allCharts.Count})
- Series {seriesIdx} not found (total: {seriesChildren.Count})
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/c47951c1e970211a.
Report an issue: GitHub.