{"record":{"id":"749cba90622dd4b3","repo":"iOfficeAI/OfficeCLI","slug":"sheet-has-no-drawings-charts","errorCode":null,"errorMessage":"Sheet has no drawings/charts","messagePattern":"Sheet has no drawings/charts","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs","lineNumber":385,"sourceCode":"    }\n\n    // BUG-002: `add /SheetName/chart[N] --type chart-series` — append a data\n    // series to an existing chart. Mirrors PowerPointHandler.AddChartSeries\n    // (R22-1); additionally resolves xlsx cell-range values/categories into\n    // numRef/strRef + cached snapshot, matching what chart Add emits for\n    // range-referenced series (CONSISTENCY(chart-series-rangeref-cache)).\n    private string AddChartSeries(string parentPath, Dictionary<string, string> properties)\n    {\n        var m = Regex.Match(parentPath, @\"^/([^/]+)/chart\\[(\\d+)\\]$\");\n        if (!m.Success)\n            throw new ArgumentException(\n                \"series must be added to a chart parent: /SheetName/chart[N]\");\n        var sheetName = m.Groups[1].Value;\n        var chartIdx = int.Parse(m.Groups[2].Value);\n        var worksheet = FindWorksheet(sheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {sheetName}\");\n        var drawingsPart = worksheet.DrawingsPart\n            ?? throw new ArgumentException(\"Sheet has no drawings/charts\");\n        var excelCharts = GetExcelCharts(drawingsPart);\n        if (chartIdx < 1 || chartIdx > excelCharts.Count)\n            throw new ArgumentException($\"Chart {chartIdx} not found (total: {excelCharts.Count})\");\n        var chartInfo = excelCharts[chartIdx - 1];\n        if (chartInfo.StandardPart == null)\n            throw new ArgumentException(\n                $\"Chart at {parentPath} is not a standard chart (extended cx charts do not support add series).\");\n        var chartPart = chartInfo.StandardPart;\n\n        // Resolve range-reference values/categories against the workbook so\n        // AddSeries seeds literal data (which becomes the cached snapshot).\n        // Mutate `properties` in place instead of copying: enumerating a\n        // TrackingPropertyDictionary into a fresh dict marks EVERY key as\n        // consumed (see TrackingPropertyDictionary.GetEnumerator), which\n        // silently swallows unsupported_property reporting for unknown keys.\n        // TryGetValue / indexer / Remove are the tracked access routes.\n        string? valuesRef = null, categoriesRef = null;\n        List<string>? cachedCats = null;","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs#L367-L403","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["First create a chart on the sheet with add /Sheet1/chart --type chart --chartType bar --data ..., then add series to it.","Verify the chart exists by listing drawings on the sheet before attempting add-series.","If drawings were deleted, recreate the chart from scratch."],"exampleFix":"// before (sheet has no charts yet)\nadd /Sheet1/chart[1] --type chart-series --data \"S2:5,6,7\"\n// after (create the chart first, then append)\nadd /Sheet1/chart --type chart --chartType bar --data \"S1:1,2,3\"\nadd /Sheet1/chart[1] --type chart-series --data \"S2:5,6,7\"","handlingStrategy":"validation","validationCode":"// Check the worksheet has drawings before appending a series\nvar worksheet = handler.FindWorksheet(sheetName);\nif (worksheet?.DrawingsPart == null)\n    throw new InvalidOperationException(\n        $\"Sheet '{sheetName}' has no drawings/charts. Create a chart first.\");","typeGuard":null,"tryCatchPattern":"try { handler.AddChartSeries(parentPath, properties); }\ncatch (ArgumentException ex) when (ex.Message == \"Sheet has no drawings/charts\")\n{\n    Console.Error.WriteLine($\"{ex.Message} Create a chart on this sheet first.\");\n}","preventionTips":["Always create at least one chart on a sheet before attempting to append series.","Check worksheet.DrawingsPart != null before calling AddChartSeries.","Distinguish between 'create new chart' (add chart) and 'append series' (add chart-series) operations."],"tags":["excel","chart","series","drawings","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}