{"record":{"id":"195e79864a6a10d2","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-fbsheetname","errorCode":null,"errorMessage":"Sheet not found: {fbSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs","lineNumber":441,"sourceCode":"\n        var newIdx = ChartHelper.AddSeries(chartPart, properties);\n        if (newIdx == 0)\n            throw new ArgumentException(\n                \"Cannot add a series: the chart has no existing series to derive structure from. Recreate the chart with the desired series instead.\");\n        ChartHelper.ApplySeriesRangeRefs(chartPart, newIdx, valuesRef, categoriesRef, cachedCats);\n        return $\"/{sheetName}/chart[{chartIdx}]/series[{newIdx}]\";\n    }\n\n    private string AddDefault(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        // Generic fallback: create typed element via SDK schema validation\n        // Parse parentPath: /<SheetName>/xmlPath...\n        var fbSegments = parentPath.TrimStart('/').Split('/', 2);\n        var fbSheetName = fbSegments[0];\n        var fbWorksheet = FindWorksheet(fbSheetName);\n        if (fbWorksheet == null)\n            throw new ArgumentException($\"Sheet not found: {fbSheetName}\");\n\n        OpenXmlElement fbParent = GetSheet(fbWorksheet);\n        if (fbSegments.Length > 1 && !string.IsNullOrEmpty(fbSegments[1]))\n        {\n            var xmlSegments = GenericXmlQuery.ParsePathSegments(fbSegments[1]);\n            fbParent = GenericXmlQuery.NavigateByPath(fbParent!, xmlSegments)\n                ?? throw new ArgumentException($\"Parent element not found: {parentPath}\");\n        }\n\n        var created = GenericXmlQuery.TryCreateTypedElement(fbParent!, type, properties, index);\n        if (created == null)\n            throw new ArgumentException(\n                $\"Unknown element type '{type}' for {parentPath}. \" +\n                \"Valid types: sheet, row, cell, shape, chart, ole (object, embed), autofilter, databar, colorscale, iconset, formulacf, comment, namedrange, table, picture, validation, pivottable. \" +\n                \"Use 'officecli xlsx add' for details.\");\n\n        SaveWorksheet(fbWorksheet);\n","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs#L423-L459","documentation":"Thrown by the AddDefault fallback method when the sheet name extracted from the parentPath does not resolve to an existing worksheet. The path is split on the first '/' after trimming the leading slash; the first segment is the sheet name. This is the generic-add counterpart to the chart-series sheet-not-found check.","triggerScenarios":"Calling add /NonExistentSheet/someElement --type cell or any generic add where the first path segment names a sheet that does not exist in the workbook.","commonSituations":"Sheet was renamed or deleted. Typo or casing mismatch in the sheet name. Script runs against a different workbook than expected.","solutions":["List worksheets to get the exact sheet name and update the path.","Check for trailing spaces or case mismatches.","Create the sheet first if it should exist.","Verify the correct workbook file is being edited."],"exampleFix":"// before (sheet is named 'Summary')\nadd /summry/A1 --type cell --value \"hello\"\n// after\nadd /Summary/A1 --type cell --value \"hello\"","handlingStrategy":"validation","validationCode":"// Validate the sheet exists before calling AddDefault\nvar segments = parentPath.TrimStart('/').Split('/', 2);\nvar sheetName = segments[0];\nif (handler.FindWorksheet(sheetName) == null)\n    throw new InvalidOperationException($\"Sheet not found: {sheetName}\");","typeGuard":null,"tryCatchPattern":"try { handler.AddDefault(parentPath, type, position, properties); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found:\"))\n{\n    Console.Error.WriteLine($\"{ex.Message} Verify the sheet name and casing.\");\n}","preventionTips":["List worksheets and copy the exact name before constructing a path.","Validate the first path segment against known worksheet names.","Watch for trailing spaces and casing differences.","Create the sheet first if it does not exist."],"tags":["excel","add","sheet-not-found","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}