{"record":{"id":"ecd89b87a8998df1","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-dvsheetname","errorCode":null,"errorMessage":"Sheet not found: {dvSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":507,"sourceCode":"                return rowEl != null && colEl != null\n                    && int.TryParse(rowEl.Value.Trim(), out var r) && r == row0\n                    && int.TryParse(colEl.Value.Trim(), out var c) && c == col0;\n            });\n            if (target == null) return;\n            target.Remove();\n            using var wstream = vmlPart.GetStream(System.IO.FileMode.Create, System.IO.FileAccess.Write);\n            vmlDoc.Save(wstream);\n        }\n        catch { }\n    }\n\n    private string AddValidation(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)\n    {\n        var index = position?.Index;\n        var dvSegments = parentPath.TrimStart('/').Split('/', 2);\n        var dvSheetName = dvSegments[0];\n        var dvWorksheet = FindWorksheet(dvSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {dvSheetName}\");\n\n        // CONSISTENCY(range-alias): cf/colorscale/iconset/pivottable all take\n        // sqref/range/ref interchangeably; validation lacked `range` only.\n        var dvSqref = properties.GetValueOrDefault(\"sqref\")\n            ?? properties.GetValueOrDefault(\"range\")\n            ?? properties.GetValueOrDefault(\"ref\")\n            ?? throw new ArgumentException(\"Property 'sqref' (or 'range'/'ref') is required for validation\");\n\n        // NOTE: multi-region sqref (\"A1:A5 C1:C5\") is legal and opens fine in\n        // real Excel — a fuzz report claiming otherwise was a render-service\n        // cache false positive (fresh-content retest and an openpyxl gold\n        // sample both open cleanly). Do not add a guard for multi-region —\n        // but DO validate each token's A1 shape: an arbitrary string landed\n        // verbatim in sqref= and real Excel refused the file (0x800A03EC)\n        // while schema validation stayed green.\n        dvSqref = ValidateSqref(dvSqref, \"validation ref\");\n\n        var dv = new DataValidation","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L489-L525","documentation":"Thrown by AddValidation when FindWorksheet(dvSheetName) returns null. dvSheetName is the first segment of parentPath after trimming '/'. Same plain 'Sheet not found: <name>' inline form used by AddComment.","triggerScenarios":"Call Add type \"validation\"/\"datavalidation\" with a parentPath whose first segment names no worksheet, e.g. \"/BadSheet\".","commonSituations":"Sheet-name typo; sheet renamed/deleted; path copied from a different workbook; locale-specific sheet name with characters that need exact spelling.","solutions":["Verify the name against handler.GetDumpSheetNames() and use the exact spelling.","Correct the first parentPath segment (case-insensitive match).","Create the sheet first if it is genuinely missing."],"exampleFix":"// before\nhandler.Add(\"/Sheat1\", \"validation\", null, new() { [\"sqref\"] = \"A1:A5\", [\"type\"] = \"whole\" });\n// after\nhandler.Add(\"/Sheet1\", \"validation\", null, new() { [\"sqref\"] = \"A1:A5\", [\"type\"] = \"whole\" });","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 dynamically via GetDumpSheetNames().","Validate the parentPath first segment before every validation add.","Guard against empty sheet names from malformed paths."],"tags":["excel","sheet","path","not-found","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}