iOfficeAI/OfficeCLI · error · ArgumentException

Sheet has no drawings/charts

Error message

Sheet has no drawings/charts

What it means

Thrown by AddChartSeries when the target worksheet exists but has no DrawingsPart. The DrawingsPart is the OpenXML container that holds all charts, pictures, and shapes on a sheet. A sheet that was never given any drawing cannot host a chart series because there is no chart part to append to.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs:385

    }

    // 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).
        // Mutate `properties` in place instead of copying: enumerating a
        // TrackingPropertyDictionary into a fresh dict marks EVERY key as
        // consumed (see TrackingPropertyDictionary.GetEnumerator), which
        // silently swallows unsupported_property reporting for unknown keys.
        // TryGetValue / indexer / Remove are the tracked access routes.
        string? valuesRef = null, categoriesRef = null;
        List<string>? cachedCats = null;

View on GitHub (pinned to 1ced45e900)

Solutions

  1. First create a chart on the sheet with add /Sheet1/chart --type chart --chartType bar --data ..., then add series to it.
  2. Verify the chart exists by listing drawings on the sheet before attempting add-series.
  3. If drawings were deleted, recreate the chart from scratch.

Example fix

// before (sheet has no charts yet)
add /Sheet1/chart[1] --type chart-series --data "S2:5,6,7"
// after (create the chart first, then append)
add /Sheet1/chart --type chart --chartType bar --data "S1:1,2,3"
add /Sheet1/chart[1] --type chart-series --data "S2:5,6,7"
Defensive patterns

Strategy: validation

Validate before calling

// Check the worksheet has drawings before appending a series
var worksheet = handler.FindWorksheet(sheetName);
if (worksheet?.DrawingsPart == null)
    throw new InvalidOperationException(
        $"Sheet '{sheetName}' has no drawings/charts. Create a chart first.");

Try / catch

try { handler.AddChartSeries(parentPath, properties); }
catch (ArgumentException ex) when (ex.Message == "Sheet has no drawings/charts")
{
    Console.Error.WriteLine($"{ex.Message} Create a chart on this sheet first.");
}

Prevention

When it happens

Trigger: Calling add /Sheet1/chart[1] --type chart-series on a sheet that has zero charts, pictures, or shapes. The worksheet object exists (FindWorksheet succeeded) but worksheet.DrawingsPart is null.

Common situations: User targets a freshly created or data-only sheet that has never had a chart added. User deleted all drawings from a sheet and then tries to append a series. Confusion between adding a series to an existing chart vs. creating a new chart.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/749cba90622dd4b3. Report an issue: GitHub.