iOfficeAI/OfficeCLI · error · ArgumentException
SharedString entry {sstIdx} not found
Error message
SharedString entry {sstIdx} not found What it means
Thrown in the run[N] path when the cell IS a SharedString cell and points at index sstIdx, but the SharedStringTable has no entry at that index (ElementAtOrDefault returns null). This indicates a corrupt or hand-edited file whose cell references a shared-string index that does not exist — the data is internally inconsistent.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Query.cs:933
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]);
return GetCellRange(sheetNameFromPath, data, cellRef, depth, worksheet);
}
else
{
// Single cell — validate cell reference
ParseCellReference(cellRef);View on GitHub (pinned to 1ced45e900)
Solutions
- Open and re-save the workbook in Excel/another conforming writer to rebuild the shared-strings table.
- Validate the file with the Open XML SDK or an OOXML validator to locate the desynchronization.
- If you control the producer, ensure every SharedString cell value is written through the SharedStringTable, not hand-set.
Example fix
// no code fix — repair the source workbook so shared-string indices are valid
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try:
doc.get('/Sheet1/A1/run[1]')
except officecli.OfficeCliError as e:
if 'SharedString entry' in str(e):
# corrupt file: shared-string index is stale
repair_or_reexport_workbook(path) Prevention
- Validate the OOXML with the Open XML SDK before querying runs.
- Re-save corrupt files in Excel to rebuild the shared-strings table.
- Avoid hand-editing sheetData/sharedStrings.xml; always write through a conforming producer.
When it happens
Trigger: A cell whose CellValue is an integer but that integer exceeds the SharedStringTable entry count, or the table is missing entirely. Reached only for cells that passed the 'is rich text cell' check (DataType == SharedString, integer value) but whose index is stale.
Common situations: Files edited by non-conforming tools, partial/corrupt exports, manual XML edits to sheetData or sharedStrings.xml that desynchronize the index, or a file where the shared-strings part was stripped.
Related errors
- Cell {runCellRef} not found
- Workbook not found
- Sheet not found: {cmtSheetName}
- Sheet not found: {dvSheetName}
- Sheet not found: {afSheetName}
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/4e8c8b4baffa8876.
Report an issue: GitHub.