{"record":{"id":"aaa7d550ad3cef95","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-issheetname","errorCode":null,"errorMessage":"Sheet not found: {isSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs","lineNumber":373,"sourceCode":"            SequenceOfReferences = new ListValue<StringValue>(\n                csSqref.Split(' ').Select(s => new StringValue(s)))\n        };\n\n        var csWsElement = GetSheet(csWorksheet);\n        InsertConditionalFormatting(csWsElement, csCf);\n\n        SaveWorksheet(csWorksheet);\n        var csCfCount = csWsElement.Elements<ConditionalFormatting>().Count();\n        return $\"/{csSheetName}/cf[{csCfCount}]\";\n    }\n\n    private string AddIconSet(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var isSegments = parentPath.TrimStart('/').Split('/', 2);\n        var isSheetName = isSegments[0];\n        var isWorksheet = FindWorksheet(isSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {isSheetName}\");\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 isPathRange = isSegments.Length > 1 && !string.IsNullOrEmpty(isSegments[1]) ? isSegments[1] : \"A1:A10\";\n        var isSqref = ValidateSqref(properties.GetValueOrDefault(\"sqref\") ?? properties.GetValueOrDefault(\"range\") ?? properties.GetValueOrDefault(\"ref\", isPathRange), \"ref\");\n        var iconSetName = properties.GetValueOrDefault(\"iconset\") ?? properties.GetValueOrDefault(\"icons\", \"3TrafficLights1\");\n        var reverse = properties.TryGetValue(\"reverse\", out var revVal) && IsTruthy(revVal);\n        var showValue = !properties.TryGetValue(\"showvalue\", out var svVal) || IsTruthy(svVal);\n\n        var iconSetVal = ParseIconSetValues(iconSetName);\n\n        var iconSet = new IconSet { IconSetValue = iconSetVal };\n        if (reverse) iconSet.Reverse = true;\n        if (!showValue) iconSet.ShowValue = false;\n\n        // Add threshold values based on icon count\n        var iconCount = GetIconCount(iconSetName);\n        for (int i = 0; i < iconCount; i++)","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Cf.cs#L355-L391","documentation":"Thrown by AddIconSet when the first segment of parentPath (the sheet name) does not resolve to any worksheet via FindWorksheet (case-insensitive). The icon set rule needs a target worksheet element to attach the <conditionalFormatting> child to; without one, there is no attachment point.","triggerScenarios":"Calling Add with parentPath '/<sheet>/...' and type=iconset (or cf type=iconset) where <sheet> is not a worksheet in the workbook. Triggered identically by a typo, a stale name, or a mis-split path.","commonSituations":"Referencing a sheet that was deleted; case mismatch is tolerated but a genuine name difference is not; using the chart-sheet or macro-sheet label instead of a worksheet name.","solutions":["Verify the sheet name exists in the workbook and use it exactly as segment[0] of the path.","Create the sheet first if it is missing.","Confirm the path format is '/SheetName/Range' so the split puts the name in segment[0]."],"exampleFix":"// before: sheet 'Summary' missing\nadd /Summary/A1:A10 iconset iconset=3TrafficLights1\n// after: ensure sheet exists\nadd-sheet Summary\nadd /Summary/A1:A10 iconset iconset=3TrafficLights1","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, \"iconset\", pos, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found\"))\n{ /* list sheets, let user correct path, retry */ throw; }","preventionTips":["Validate the sheet token against the live sheet list before calling Add.","Create the sheet first if missing.","Keep the path format '/SheetName/Range'."],"tags":["excel","conditional-formatting","iconset","sheet-resolution","path-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}