{"record":{"id":"ad1744e5c00d0761","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-cfnewsheetname","errorCode":null,"errorMessage":"Sheet not found: {cfNewSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs","lineNumber":637,"sourceCode":"            SequenceOfReferences = new ListValue<StringValue>(\n                cisSqref.Split(' ').Select(s => new StringValue(s)))\n        };\n\n        var cisWsElement = GetSheet(cisWorksheet);\n        InsertConditionalFormatting(cisWsElement, cisCf);\n\n        SaveWorksheet(cisWorksheet);\n        var cisCfCount = cisWsElement.Elements<ConditionalFormatting>().Count();\n        return $\"/{cisSheetName}/cf[{cisCfCount}]\";\n    }\n\n    private string AddCfExtended(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var cfNewSegments = parentPath.TrimStart('/').Split('/', 2);\n        var cfNewSheetName = cfNewSegments[0];\n        var cfNewWorksheet = FindWorksheet(cfNewSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {cfNewSheetName}\");\n        // R22-2: path-tail range is the fallback before the hardcoded default.\n        var cfNewPathRange = cfNewSegments.Length > 1 && !string.IsNullOrEmpty(cfNewSegments[1]) ? cfNewSegments[1] : \"A1:A10\";\n        var cfNewSqref = ValidateSqref(properties.GetValueOrDefault(\"sqref\") ?? properties.GetValueOrDefault(\"range\") ?? properties.GetValueOrDefault(\"ref\", cfNewPathRange), \"ref\");\n        var cfNewPriority = NextCfPriority(GetSheet(cfNewWorksheet));\n\n        ConditionalFormattingRule cfNewRule;\n        var typeLower = type.ToLowerInvariant();\n        // For cfextended dispatch, the actual requested sub-type is in\n        // properties[\"type\"] (the user-facing switch; the outer `type`\n        // variable is literal \"cfextended\" here).\n        if (typeLower == \"cfextended\")\n            typeLower = (properties.GetValueOrDefault(\"type\", \"\") ?? \"\").ToLowerInvariant();\n\n        switch (typeLower)\n        {\n            case \"topn\":\n            {\n                // Accept `rank=` (OOXML attribute name), `top=`/`bottomN=` (legacy","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs#L619-L655","documentation":"Thrown by AddCfExtended when the first segment of parentPath does not resolve to a worksheet. AddCfExtended handles the extended CF family (top10/aboveAverage/uniqueValues/duplicateValues/containsText/dateOccurring/blanks/errors/beginsWith/endsWith). The sheet segment is split from parentPath and looked up case-insensitively.","triggerScenarios":"Calling Add with parentPath '/<sheet>/...' and any cfextended-routed type (topn, aboveaverage, uniquevalues, duplicatevalues, containstext, dateoccurring, belowaverage, containsblanks, notcontainsblanks, containserrors, notcontainserrors, contains, notcontains, beginswith, endswith) where <sheet> is not found.","commonSituations":"Renamed/deleted sheet; typo; path built from untrusted input without sheet validation; using a chart-sheet name where a worksheet is required.","solutions":["Confirm the worksheet name and use it as segment[0].","Create the sheet first.","Re-enumerate sheets to get current names."],"exampleFix":"// before: 'Metrics' sheet missing\nadd /Metrics/A1:A10 cf type=topn value=5\n// after\nadd-sheet Metrics\nadd /Metrics/A1:A10 cf type=topn value=5","handlingStrategy":"validation","validationCode":"var sheet = parentPath.TrimStart('/').Split('/', 2)[0];\nif (FindWorksheet(sheet) is null)\n    throw new ArgumentException($\"Sheet '{sheet}' not found.\");","typeGuard":"static bool SheetExists(string? sheetName, IEnumerable<string> known)\n    => sheetName is not null && known.Contains(sheetName, StringComparer.OrdinalIgnoreCase);","tryCatchPattern":"try { return Add(path, \"cfextended\", pos, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found\"))\n{ /* correct sheet, retry */ throw; }","preventionTips":["Resolve the sheet name against the workbook before the call.","Create the sheet first if missing.","Use the exact stored name."],"tags":["excel","conditional-formatting","cfextended","sheet-resolution","path-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}