{"record":{"id":"3950ed814654e690","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-cssheetname","errorCode":null,"errorMessage":"Sheet not found: {csSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs","lineNumber":286,"sourceCode":"        var x14Cf = new X14.ConditionalFormatting();\n        x14Cf.AddNamespaceDeclaration(\"xm\", \"http://schemas.microsoft.com/office/excel/2006/main\");\n        x14Cf.Append(x14CfRule);\n        x14Cf.Append(new DocumentFormat.OpenXml.Office.Excel.ReferenceSequence(sqref));\n\n        EnsureWorksheetX14ConditionalFormatting(wsElement, x14Cf);\n\n        SaveWorksheet(cfWorksheet);\n        var dbCfCount = wsElement.Elements<ConditionalFormatting>().Count();\n        return $\"/{cfSheetName}/cf[{dbCfCount}]\";\n    }\n\n    private string AddColorScale(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var csSegments = parentPath.TrimStart('/').Split('/', 2);\n        var csSheetName = csSegments[0];\n        var csWorksheet = FindWorksheet(csSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {csSheetName}\");\n\n        // CONSISTENCY(cf-sqref): three-level fallback matches dataBar/formulacf branches.\n        // R22-2: path-tail range is the fallback before the hardcoded default.\n        var csPathRange = csSegments.Length > 1 && !string.IsNullOrEmpty(csSegments[1]) ? csSegments[1] : \"A1:A10\";\n        var csSqref = ValidateSqref(properties.GetValueOrDefault(\"sqref\") ?? properties.GetValueOrDefault(\"range\") ?? properties.GetValueOrDefault(\"ref\", csPathRange), \"ref\");\n        var minColor = properties.GetValueOrDefault(\"mincolor\", \"F8696B\");\n        var maxColor = properties.GetValueOrDefault(\"maxcolor\", \"63BE7B\");\n        var midColor = properties.GetValueOrDefault(\"midcolor\");\n\n        var normalizedMinColor = ParseHelpers.NormalizeArgbColor(minColor);\n        var normalizedMaxColor = ParseHelpers.NormalizeArgbColor(maxColor);\n\n        // CF5 — accept user-supplied midpoint (`midpoint=50`, default 50).\n        // Lenient forms: \"50\", \"50%\" (percent → percentile), and prefixed\n        // \"percentile:50\" / \"percent:50\" / \"num:50\". Anything else must be\n        // rejected: an unparsed value (\"50%\", \"percentile:50\") used to land\n        // verbatim in <cfvo val=>, which passes schema validation but real\n        // Excel refuses the whole file (0x800A03EC).","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs#L268-L304","documentation":"Thrown by AddColorScale when the first segment of the parentPath (the sheet name) does not resolve to any worksheet in the open workbook. The parentPath is split on '/', segment[0] is the sheet name, and FindWorksheet does a case-insensitive lookup. This is a path-resolution failure: the color scale rule has nowhere to attach.","triggerScenarios":"Calling Add with parentPath like '/NonExistentSheet/A1:A10' and type=colorscale (or cf type=colorscale), where 'NonExistentSheet' is not a worksheet name in the current workbook. Also triggered when the path omits the leading '/' and the whole path collapses into segment[0].","commonSituations":"Sheet was renamed or deleted between sessions; typo in sheet name; using a 1-based display index instead of the name; workbook loaded from a template whose default sheet name differs (Sheet1 vs Sheet 1 vs Tabelle1).","solutions":["List the workbook's sheets (e.g. via a list/listing command) and use the exact name as segment[0] of the path.","If the sheet does not exist, create it first with an add-sheet operation before adding the color scale.","Ensure the parentPath is '/SheetName/Range' — the sheet name is the first segment after trimming the leading '/'."],"exampleFix":"// before: sheet 'Data' does not exist\nadd /Data/A1:A10 colorscale mincolor=F8696B maxcolor=63BE7B\n// after: create the sheet first, then add the rule\nadd-sheet Data\nadd /Data/A1:A10 colorscale mincolor=F8696B maxcolor=63BE7B","handlingStrategy":"validation","validationCode":"var sheet = parentPath.TrimStart('/').Split('/', 2)[0];\nif (FindWorksheet(sheet) is null)\n    throw new ArgumentException($\"Sheet '{sheet}' not found. Available: {string.Join(\", \", GetWorksheets().Select(w => w.Name))}\");","typeGuard":"static bool SheetExists(string? sheetName, IEnumerable<string> known)\n    => sheetName is not null && known.Contains(sheetName, StringComparer.OrdinalIgnoreCase);","tryCatchPattern":"try { return Add(path, \"colorscale\", pos, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found\"))\n{ /* prompt user to pick from available sheets, then retry */ throw; }","preventionTips":["Resolve the sheet name against the workbook's sheet list before constructing the path.","Prefer the exact stored name over a display label or index.","Create the sheet in a prior step if it may not exist."],"tags":["excel","conditional-formatting","colorscale","sheet-resolution","path-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}