{"record":{"id":"c1ecae914f73f36f","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-afsheetname","errorCode":null,"errorMessage":"Sheet not found: {afSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":721,"sourceCode":"        dvs.AppendChild(dv);\n        dvs.Count = (uint)dvs.Elements<DataValidation>().Count();\n\n        SaveWorksheet(dvWorksheet);\n        var dvIndex = PathIndex.FromArrayIndex(dvs.Elements<DataValidation>().ToList().IndexOf(dv));\n        // CONSISTENCY(path-segment-naming): the path segment must match the\n        // type name the caller used in `add` (`dataValidation`). The legacy\n        // `/validation[N]` form remains accepted by Get / Set / Remove as an\n        // alias for back-compat (R7-bt-6).\n        return $\"/{dvSheetName}/dataValidation[{dvIndex}]\";\n    }\n\n    private string AddAutoFilter(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var afSegments = parentPath.TrimStart('/').Split('/', 2);\n        var afSheetName = afSegments[0];\n        var afWorksheet = FindWorksheet(afSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {afSheetName}\");\n\n        // CONSISTENCY(tracking-rebind): the criteriaN.OP loop below iterates\n        // properties via foreach over the static Dictionary<,> type, which\n        // bypasses TrackingPropertyDictionary's comparer. Mark every\n        // criteriaN.OP key (and `range`) as consumed up-front so they\n        // don't surface as false unsupported_property warnings. Keys that\n        // don't match either pattern fall through to the existing UNSUPPORTED\n        // path naturally.\n        if (properties is OfficeCli.Core.TrackingPropertyDictionary afTracking)\n        {\n            var consumed = properties.Keys\n                .Where(k => string.Equals(k, \"range\", StringComparison.OrdinalIgnoreCase)\n                    || Regex.IsMatch(k, @\"^criteria\\d+\\.[A-Za-z]+$\"))\n                .ToList();\n            afTracking.MarkAllConsumed(consumed);\n        }\n\n        var afRange = properties.GetValueOrDefault(\"range\")","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L703-L739","documentation":"Thrown by AddAutoFilter when FindWorksheet(afSheetName) returns null. afSheetName is the first segment of parentPath after trimming '/'. Same plain 'Sheet not found: <name>' inline form used by the comment/validation adders.","triggerScenarios":"Call Add type \"autofilter\" with a parentPath whose first segment names no worksheet, e.g. \"/Data2\" when the sheet is \"Data\".","commonSituations":"Sheet-name typo; sheet renamed/deleted; path copied from another workbook; index-based sheet reference that did not resolve.","solutions":["Verify against handler.GetDumpSheetNames() and use the exact name.","Correct the first parentPath segment (case-insensitive match).","Create the sheet first if it is genuinely missing."],"exampleFix":"// before\nhandler.Add(\"/Data2\", \"autofilter\", null, new() { [\"range\"] = \"A1:F100\" });\n// after\nhandler.Add(\"/Data\", \"autofilter\", null, new() { [\"range\"] = \"A1:F100\" });","handlingStrategy":"validation","validationCode":"var sheet = parentPath.TrimStart('/').Split('/', 2)[0];\nif (!handler.GetDumpSheetNames()\n        .Any(n => n.Equals(sheet, StringComparison.OrdinalIgnoreCase)))\n    throw new InvalidOperationException($\"No sheet '{sheet}'. Available: \" +\n        string.Join(\", \", handler.GetDumpSheetNames()));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve sheet names from GetDumpSheetNames() rather than literals.","Validate the parentPath first segment before every autofilter add.","Re-check the sheet list after structural changes in the same run."],"tags":["excel","sheet","path","not-found","autofilter"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}