iOfficeAI/OfficeCLI · error · ArgumentException

Cell {runCellRef} not found

Error message

Cell {runCellRef} not found

What it means

Thrown in the rich-text run direct-access path (A1/run[N]). The cell reference parses successfully (ParseCellReference passes) but FindCell returns null — the coordinate is valid but the cell does not exist in the sheet (it is empty/never written). Without a cell there is no shared-string index and no runs to index.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Query.cs:927

            // Generic XML fallback: navigate worksheet XML tree
            var xmlSegments = GenericXmlQuery.ParsePathSegments(cellRef);
            var target = GenericXmlQuery.NavigateByPath(GetSheet(worksheet), xmlSegments);
            if (target == null)
                return new DocumentNode { Path = path, Type = "error", Text = $"Element not found: {cellRef}" };
            return GenericXmlQuery.ElementToNode(target, path, depth);
        }

        // Handle /SheetName/A1/run[N] (rich text run direct access)
        var runGetMatch = Regex.Match(cellRef, @"^([A-Z]+\d+)/run\[(\d+)\]$", RegexOptions.IgnoreCase);
        if (runGetMatch.Success)
        {
            var runCellRef = runGetMatch.Groups[1].Value.ToUpperInvariant();
            var runIdx = int.Parse(runGetMatch.Groups[2].Value);
            ParseCellReference(runCellRef);
            var runCell = FindCell(data, runCellRef);
            if (runCell == null)
                throw new ArgumentException($"Cell {runCellRef} not found");
            if (runCell.DataType?.Value != CellValues.SharedString ||
                !int.TryParse(runCell.CellValue?.Text, out var sstIdx))
                throw new ArgumentException($"Cell {runCellRef} is not a rich text cell");
            var sstPart = _doc.WorkbookPart?.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
            var ssi = sstPart?.SharedStringTable?.Elements<SharedStringItem>().ElementAtOrDefault(sstIdx);
            if (ssi == null) throw new ArgumentException($"SharedString entry {sstIdx} not found");
            var runs = ssi.Elements<Run>().ToList();
            if (runIdx < 1 || runIdx > runs.Count)
                throw new ArgumentException($"Run index {runIdx} out of range (1-{runs.Count})");
            return RunToNode(runs[PathIndex.ToArrayIndex(runIdx)], $"/{sheetNameFromPath}/{runCellRef}/run[{runIdx}]");
        }

        if (cellRef.Contains(':'))
        {
            // Range — validate both endpoints
            var rangeParts = cellRef.Split(':');
            ParseCellReference(rangeParts[0]);
            if (rangeParts.Length > 1) ParseCellReference(rangeParts[1]);

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Verify the cell exists first: get /Sheet1/Z99 and confirm it returns a value before appending /run[N].
  2. Correct the coordinate to a cell known to contain rich/shared-string text.
  3. If iterating, restrict your loop to the sheet's used range so you only hit populated cells.

Example fix

// before
get /Sheet1/Z99/run[1]
// after
get /Sheet1/A1/run[1]   // A1 actually contains rich text
Defensive patterns

Strategy: validation

Validate before calling

# verify the cell exists before requesting a run
node = doc.get('/Sheet1/Z99')
if node.get('type') == 'error' or not node.get('text'):
    raise SystemExit('cell is empty — no runs to index')
doc.get('/Sheet1/Z99/run[1]')

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: get /Sheet1/Z99/run[1] where Z99 is empty; any A1/run[N] against a cell that has no value. ParseCellReference already validated the A1 shape, so only truly absent cells reach here.

Common situations: Reading runs from a cell the user assumes has rich text but is blank; off-by-one in a generated coordinate; querying a sheet region beyond the used range.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/e709e8558489da79. Report an issue: GitHub.