{"record":{"id":"fc8d7a8d0d42ca9c","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-fcfsheetname","errorCode":null,"errorMessage":"Sheet not found: {fcfSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs","lineNumber":435,"sourceCode":"            SequenceOfReferences = new ListValue<StringValue>(\n                isSqref.Split(' ').Select(s => new StringValue(s)))\n        };\n\n        var isWsElement = GetSheet(isWorksheet);\n        InsertConditionalFormatting(isWsElement, isCf);\n\n        SaveWorksheet(isWorksheet);\n        var isCfCount = isWsElement.Elements<ConditionalFormatting>().Count();\n        return $\"/{isSheetName}/cf[{isCfCount}]\";\n    }\n\n    private string AddFormulaCf(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var fcfSegments = parentPath.TrimStart('/').Split('/', 2);\n        var fcfSheetName = fcfSegments[0];\n        var fcfWorksheet = FindWorksheet(fcfSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {fcfSheetName}\");\n\n        // CONSISTENCY(cf-sqref): three-level fallback matches dataBar/colorScale branches.\n        // R22-2: path-tail range is the fallback before the hardcoded default.\n        var fcfPathRange = fcfSegments.Length > 1 && !string.IsNullOrEmpty(fcfSegments[1]) ? fcfSegments[1] : \"A1:A10\";\n        var fcfSqref = ValidateSqref(properties.GetValueOrDefault(\"sqref\") ?? properties.GetValueOrDefault(\"range\") ?? properties.GetValueOrDefault(\"ref\", fcfPathRange), \"ref\");\n        // CONSISTENCY(cf-value-alias): the help schema documents value/\n        // formula1 as aliases of formula, and the cellIs branch already\n        // accepts them — the formula branch alone rejected the alias.\n        var fcfFormula = properties.GetValueOrDefault(\"formula\")\n            ?? properties.GetValueOrDefault(\"formula1\")\n            ?? properties.GetValueOrDefault(\"value\")\n            ?? throw new ArgumentException(\"Formula-based conditional formatting requires 'formula' property (e.g. formula=$A1>100)\");\n        // The <x:formula> element is A1-only — an R1C1-style reference makes\n        // real Excel refuse the file (0x800A03EC) while schema validation\n        // stays green. Same guard cell formulas already get.\n        ValidateNoR1C1Reference(fcfFormula);\n        ValidateFormulaLength(fcfFormula, \"conditional-format formula\");\n","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs#L417-L453","documentation":"Thrown by AddFormulaCf when the first segment of parentPath does not resolve to a worksheet. The formula-based (expression) conditional format needs the target worksheet to attach the rule and to compute priority via NextCfPriority(GetSheet(...)).","triggerScenarios":"Calling Add with parentPath '/<sheet>/...' and type=formula (or cf type=formula/expression, or formulacf) where <sheet> is not found. The lookup is case-insensitive but an absent or renamed sheet fails.","commonSituations":"Stale sheet name from a prior session; path constructed dynamically from user input without validating the sheet exists; workbook created from a template with localized default sheet names.","solutions":["Use the exact worksheet name as the first path segment.","Create the worksheet before adding the formula CF rule.","Re-list sheets to confirm current names before the call."],"exampleFix":"// before: 'Report' sheet does not exist\nadd /Report/A1:A10 formulacf formula=$A1>100\n// after\nadd-sheet Report\nadd /Report/A1:A10 formulacf formula=$A1>100","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, \"formulacf\", pos, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found\"))\n{ /* correct sheet name, retry */ throw; }","preventionTips":["Confirm the worksheet exists before constructing the formula CF path.","Create the sheet in advance if needed.","Use the stored sheet name exactly."],"tags":["excel","conditional-formatting","formula-cf","sheet-resolution","path-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}