{"record":{"id":"03b2c172b85c365e","repo":"iOfficeAI/OfficeCLI","slug":"cell-runcellref-is-not-a-rich-text-cell","errorCode":null,"errorMessage":"Cell {runCellRef} is not a rich text cell","messagePattern":"Cell (.+?) is not a rich text cell","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Query.cs","lineNumber":930,"sourceCode":"            var target = GenericXmlQuery.NavigateByPath(GetSheet(worksheet), xmlSegments);\n            if (target == null)\n                return new DocumentNode { Path = path, Type = \"error\", Text = $\"Element not found: {cellRef}\" };\n            return GenericXmlQuery.ElementToNode(target, path, depth);\n        }\n\n        // Handle /SheetName/A1/run[N] (rich text run direct access)\n        var runGetMatch = Regex.Match(cellRef, @\"^([A-Z]+\\d+)/run\\[(\\d+)\\]$\", RegexOptions.IgnoreCase);\n        if (runGetMatch.Success)\n        {\n            var runCellRef = runGetMatch.Groups[1].Value.ToUpperInvariant();\n            var runIdx = int.Parse(runGetMatch.Groups[2].Value);\n            ParseCellReference(runCellRef);\n            var runCell = FindCell(data, runCellRef);\n            if (runCell == null)\n                throw new ArgumentException($\"Cell {runCellRef} not found\");\n            if (runCell.DataType?.Value != CellValues.SharedString ||\n                !int.TryParse(runCell.CellValue?.Text, out var sstIdx))\n                throw new ArgumentException($\"Cell {runCellRef} is not a rich text cell\");\n            var sstPart = _doc.WorkbookPart?.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();\n            var ssi = sstPart?.SharedStringTable?.Elements<SharedStringItem>().ElementAtOrDefault(sstIdx);\n            if (ssi == null) throw new ArgumentException($\"SharedString entry {sstIdx} not found\");\n            var runs = ssi.Elements<Run>().ToList();\n            if (runIdx < 1 || runIdx > runs.Count)\n                throw new ArgumentException($\"Run index {runIdx} out of range (1-{runs.Count})\");\n            return RunToNode(runs[PathIndex.ToArrayIndex(runIdx)], $\"/{sheetNameFromPath}/{runCellRef}/run[{runIdx}]\");\n        }\n\n        if (cellRef.Contains(':'))\n        {\n            // Range — validate both endpoints\n            var rangeParts = cellRef.Split(':');\n            ParseCellReference(rangeParts[0]);\n            if (rangeParts.Length > 1) ParseCellReference(rangeParts[1]);\n            return GetCellRange(sheetNameFromPath, data, cellRef, depth, worksheet);\n        }\n        else","sourceCodeStart":912,"sourceCodeEnd":948,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Query.cs#L912-L948","documentation":"Thrown in the run[N] path when the target cell exists but is not a rich-text cell: its DataType is not SharedString, or its CellValue is not an integer shared-string index. Rich-text runs only exist for cells that point into the SharedStringTable, so a number, date, boolean, inline-string, or blank cell cannot have addressable runs.","triggerScenarios":"get /Sheet1/A1/run[1] where A1 holds a number (123), a formula result, a date, a boolean, or an inline string. Any cell whose DataType != SharedString or whose value is non-integer hits this guard.","commonSituations":"Assuming all text cells are rich text (many are plain shared strings with a single run, but numeric/formula cells are not); a file where formatting was cleared so the cell reverted to a plain value.","solutions":["Read the cell directly (get /Sheet1/A1) and check its type/value before requesting runs.","Use a tool/macro to convert the cell to rich text (it must become a SharedString with Run children) before indexing runs.","Target a cell that is genuinely rich text — typically one with mixed font runs."],"exampleFix":"// before\nget /Sheet1/A1/run[1]   // A1 is the number 42\n// after\nget /Sheet1/A1            // read the plain value instead","handlingStrategy":"type-guard","validationCode":"# only index runs of shared-string (rich) cells\nnode = doc.get('/Sheet1/A1')\n# the envelope exposes the cell type; rich text comes from SharedString cells\nif node.get('type') not in ('sharedstring', 'rich') and not node.get('isRichText'):\n    raise SystemExit('cell is not rich text — read its value directly')\ndoc.get('/Sheet1/A1/run[1]')","typeGuard":"def is_rich_text_cell(node):\n    \"\"\"A cell is rich-text only if it is a shared-string cell.\"\"\"\n    return bool(node.get('isRichText')) or node.get('type') in ('sharedstring', 'rich')","tryCatchPattern":"null","preventionTips":["Check the cell is a shared-string/rich-text cell before requesting runs.","Numeric, date, boolean, and inline-string cells have no addressable runs.","Read the plain value for non-rich cells instead of /run[N]."],"tags":["excel","rich-text","run","type-mismatch","get"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}