{"record":{"id":"a8d19d45539c62ef","repo":"iOfficeAI/OfficeCLI","slug":"sheet-not-found-olesheetname","errorCode":null,"errorMessage":"Sheet not found: {oleSheetName}","messagePattern":"Sheet not found: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs","lineNumber":74,"sourceCode":"        // Structure produced:\n        //   Worksheet > oleObjects > oleObject(progId, shapeId, r:id=embedRel)\n        //     > objectPr(defaultSize=0, r:id=iconRel)\n        //       > anchor(moveWithCells=1)\n        //         > from(col, colOff, row, rowOff)\n        //         > to  (col, colOff, row, rowOff)\n        //\n        // We skip the legacy VML shape that Excel historically\n        // generates as a fallback — when the modern objectPr/anchor\n        // is present, Office 2010+ renders from it directly. The\n        // constraint-required shapeId still needs a value, so we\n        // allocate one in the legal range (1-67098623) unique per\n        // worksheet. For round-trip fidelity, we also create an\n        // empty legacy VmlDrawingPart and register the shapeId\n        // there so the relationship target exists.\n        var oleSheetSegs = parentPath.TrimStart('/').Split('/', 2);\n        var oleSheetName = oleSheetSegs[0];\n        var oleWorksheet = FindWorksheet(oleSheetName)\n            ?? throw new ArgumentException($\"Sheet not found: {oleSheetName}\");\n\n        var oleSrc = OfficeCli.Core.OleHelper.RequireSource(properties);\n        OfficeCli.Core.OleHelper.WarnOnUnknownOleProps(properties);\n\n        // Embedding the workbook into itself: the source is open/locked by this\n        // resident session, so the read yields 0 bytes and produces an empty\n        // OLE payload real Excel refuses (0x800A03EC). Reject up front.\n        try\n        {\n            if (!string.IsNullOrEmpty(oleSrc) && !string.IsNullOrEmpty(_filePath)\n                && string.Equals(Path.GetFullPath(oleSrc), Path.GetFullPath(_filePath),\n                    StringComparison.OrdinalIgnoreCase))\n                throw new ArgumentException(\n                    \"Cannot embed a workbook into itself: the source file is the workbook being edited. \"\n                    + \"Embed a different file, or make a copy of the source first.\");\n        }\n        catch (ArgumentException) { throw; }\n        catch { /* path canonicalization failed — fall through to normal read */ }","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs#L56-L92","documentation":"Thrown by the OLE-add handler when the sheet name extracted from the parentPath does not resolve to an existing worksheet. The path is split on the first '/' and the first segment is the sheet name; if FindWorksheet returns null, this fires before any OLE processing begins.","triggerScenarios":"Calling add /NonExistentSheet --type ole --src object.xlsx. The worksheet with that exact name does not exist in the workbook.","commonSituations":"Sheet was renamed or deleted. Casing or whitespace mismatch. Script references a sheet from a template that was modified.","solutions":["List worksheets to confirm the exact sheet name.","Check for trailing spaces or case sensitivity.","Create the sheet if needed before adding the OLE object."],"exampleFix":"// before (sheet is 'Dashboard')\nadd /dashboard --type ole --src data.xlsx\n// after\nadd /Dashboard --type ole --src data.xlsx","handlingStrategy":"validation","validationCode":"// Check the sheet exists before calling OLE add\nvar sheetName = parentPath.TrimStart('/').Split('/', 2)[0];\nif (handler.FindWorksheet(sheetName) == null)\n    throw new InvalidOperationException($\"Sheet not found: {sheetName}\");","typeGuard":null,"tryCatchPattern":"try { handler.AddOle(parentPath, properties); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Sheet not found:\"))\n{\n    Console.Error.WriteLine($\"{ex.Message} Verify the sheet name.\");\n}","preventionTips":["List worksheets and verify the exact name before the add call.","Check casing and trailing whitespace in sheet names.","Create the target sheet if it does not exist."],"tags":["excel","ole","sheet-not-found","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}