{"record":{"id":"4774b939a1e677c9","repo":"iOfficeAI/OfficeCLI","slug":"ole-object-oleidx-not-found-at-sheetnamefrompa","errorCode":null,"errorMessage":"OLE object {oleIdx} not found at /{sheetNameFromPath} (available: {oleList.Count}).","messagePattern":"OLE object (.+?) not found at /(.+?) \\(available: (.+?)\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Query.cs","lineNumber":785,"sourceCode":"        if (slicerMatch.Success)\n        {\n            var slIdx = int.Parse(slicerMatch.Groups[1].Value);\n            if (!TryFindSlicerByIndex(worksheet, slIdx, out var slicerElem, out var slicerCache) || slicerElem == null)\n                throw new ArgumentException($\"slicer[{slIdx}] not found on sheet '{sheetNameFromPath}'\");\n            var slNode = new DocumentNode { Path = path, Type = \"slicer\" };\n            ReadSlicerProperties(slicerElem, slicerCache, slNode);\n            return slNode;\n        }\n\n        // OLE object path: /Sheet1/ole[N]\n        // CONSISTENCY(ole-alias): \"oleobject\" mirrors Add's case switch\n        var oleMatch = Regex.Match(cellRef, @\"^(?:ole|oleobject|object|embed)\\[(\\d+)\\]$\", RegexOptions.IgnoreCase);\n        if (oleMatch.Success)\n        {\n            var oleIdx = int.Parse(oleMatch.Groups[1].Value);\n            var oleList = CollectOleNodesForSheet(sheetNameFromPath, worksheet);\n            if (oleIdx < 1 || oleIdx > oleList.Count)\n                throw new ArgumentException($\"OLE object {oleIdx} not found at /{sheetNameFromPath} (available: {oleList.Count}).\");\n            return oleList[oleIdx - 1];\n        }\n\n        // Comment path: /Sheet1/comment[N]\n        var commentMatch = Regex.Match(cellRef, @\"^comment\\[(\\d+)\\]$\", RegexOptions.IgnoreCase);\n        if (commentMatch.Success)\n        {\n            var cmtIndex = int.Parse(commentMatch.Groups[1].Value);\n            var commentsPart = worksheet.WorksheetCommentsPart;\n            if (commentsPart?.Comments == null)\n                return new DocumentNode { Path = path, Type = \"error\", Text = $\"comment[{cmtIndex}] not found (sheet has no comments)\" };\n\n            var cmtList = commentsPart.Comments.GetFirstChild<CommentList>();\n            var cmtElement = cmtList?.Elements<Comment>().ElementAtOrDefault(cmtIndex - 1);\n            if (cmtElement == null)\n                return new DocumentNode { Path = path, Type = \"error\", Text = $\"comment[{cmtIndex}] not found\" };\n\n            return CommentToNode(sheetNameFromPath, cmtElement, commentsPart.Comments, cmtIndex);","sourceCodeStart":767,"sourceCodeEnd":803,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Query.cs#L767-L803","documentation":"Thrown for /Sheet/ole[N] (aliases: oleobject / object / embed) when N is outside the 1-based range [1, CollectOleNodesForSheet(...).Count]. OLE/embedded objects are gathered from the sheet's drawings/control deform; the message reports how many are available.","triggerScenarios":"handler.Get(\"/Sheet1/ole[2]\") on a sheet with one (or zero) embedded objects. ole[0]. Using an alias like /Sheet1/object[1] on a sheet with no embeds.","commonSituations":"Assuming embedded objects exist on a sheet that has none. Hard-coded index after objects were removed. Zero-based indexing.","solutions":["Use a 1-based index in [1, oleCount].","Verify the sheet has embedded objects before indexing.","try/catch(ArgumentException) and read the available count from the message."],"exampleFix":"// before\nvar ole = handler.Get(\"/Sheet1/ole[2]\"); // throws if <2 objects\n\n// after\ntry { var ole = handler.Get(\"/Sheet1/ole[2]\"); }\ncatch (ArgumentException) { /* ole index invalid */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static int? ElementIndex(string cellRef, string element)\n{\n    var m = Regex.Match(cellRef, $@\"^(?:ole|oleobject|object|embed)\\[(\\d+)$\", RegexOptions.IgnoreCase);\n    return m.Success && int.TryParse(m.Groups[1].Value, out var i) ? i : null;\n}","tryCatchPattern":"try { return handler.Get(\"/Sheet1/ole[2]\"); }\ncatch (ArgumentException ex) { /* ex.Message carries the available count */ return null; }","preventionTips":["OLE indices are 1-based — there is no index 0.","Aliases (ole/oleobject/object/embed) share one index space.","Confirm the sheet has embedded objects before indexing."],"tags":["excel","ole-object","path-index","argument-exception"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}