{"record":{"id":"497cf1ef1a82a855","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-sheetname-497cf1","errorCode":null,"errorMessage":"Sheet not found: {sheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs","lineNumber":383,"sourceCode":"        var chartIdx = CountExcelCharts(drawingsPart);\n        return $\"/{chartSheetName}/chart[{chartIdx}]\";\n    }\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.","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs#L365-L401","documentation":"Thrown by AddChartSeries when FindWorksheet returns null for the sheet name extracted from the parentPath. The sheet name is the first regex capture group from /SheetName/chart[N]; if no worksheet with that exact name exists in the workbook, this fires before any chart lookup is attempted.","triggerScenarios":"Calling add /NonExistentSheet/chart[1] --type chart-series. The sheet name is case-sensitive and must match an existing worksheet name exactly. Also fires if the sheet name has trailing spaces or was renamed after the path was constructed.","commonSituations":"Sheet was renamed or deleted between when the script was written and when it runs. Copy-paste introduces a trailing space or different casing. The path references a sheet from a different workbook.","solutions":["List the worksheets in the workbook first and copy the exact sheet name.","Check for trailing/leading whitespace or casing differences in the sheet name.","Rename the target sheet to match the path, or update the path to match the sheet.","Ensure you are operating on the correct workbook file."],"exampleFix":"// before (sheet is actually named 'Data')\nadd /data/chart[1] --type chart-series --data \"S2:5,6,7\"\n// after\nadd /Data/chart[1] --type chart-series --data \"S2:5,6,7\"","handlingStrategy":"validation","validationCode":"// Check the sheet exists before calling AddChartSeries\nvar match = System.Text.RegularExpressions.Regex.Match(parentPath, @\"^/([^/]+)/chart\\[(\\d+)\\]$\");\nif (match.Success)\n{\n    var sheetName = match.Groups[1].Value;\n    if (handler.FindWorksheet(sheetName) == null)\n        throw new InvalidOperationException($\"Sheet not found: {sheetName}\");\n}","typeGuard":null,"tryCatchPattern":"try { handler.AddChartSeries(parentPath, properties); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found:\"))\n{\n    Console.Error.WriteLine($\"{ex.Message} List worksheets to find the correct name.\");\n}","preventionTips":["List worksheets before referencing a sheet name in a path.","Copy the exact sheet name (case-sensitive) from the workbook listing.","Avoid hardcoding sheet names in scripts that may run against modified workbooks.","Use the sheet name returned by prior operations rather than constructing it manually."],"tags":["excel","chart","series","sheet-not-found","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}