iOfficeAI/OfficeCLI · error · ArgumentException
Table {tIdx} has no definition
Error message
Table {tIdx} has no definition What it means
Thrown when TableDefinitionParts[N-1].Table is null — the part exists but carries no <table> definition element. This signals a corrupt or incompletely-written table part (e.g. a dangling relationship to an empty/broken part). The code surfaces it as an explicit ArgumentException rather than NullReferenceException-ing on the subsequent access.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Query.cs:825
var tableMatch = Regex.Match(cellRef, @"^table\[(\d+)\]$", RegexOptions.IgnoreCase);
if (tableMatch.Success)
{
var tableIdx = int.Parse(tableMatch.Groups[1].Value);
return TableToNode(sheetNameFromPath, worksheet, tableIdx, depth);
}
// Table column path: /Sheet1/table[N]/columns[M] or /column[M]
var tableColMatch = Regex.Match(cellRef,
@"^table\[(\d+)\]/(?:columns|column)\[(\d+)\]$", RegexOptions.IgnoreCase);
if (tableColMatch.Success)
{
var tIdx = int.Parse(tableColMatch.Groups[1].Value);
var cIdx = int.Parse(tableColMatch.Groups[2].Value);
var tParts = worksheet.TableDefinitionParts.ToList();
if (tIdx < 1 || tIdx > tParts.Count)
throw new ArgumentException($"Table index {tIdx} out of range (1..{tParts.Count})");
var tbl = tParts[tIdx - 1].Table
?? throw new ArgumentException($"Table {tIdx} has no definition");
var tCols = tbl.GetFirstChild<TableColumns>()?.Elements<TableColumn>().ToList();
if (tCols == null || cIdx < 1 || cIdx > tCols.Count)
throw new ArgumentException($"Column index {cIdx} out of range (1..{tCols?.Count ?? 0})");
var tCol = tCols[cIdx - 1];
var tcNode = new DocumentNode
{
Path = $"/{sheetNameFromPath}/table[{tIdx}]/columns[{cIdx}]",
Type = "tableColumn",
Text = tCol.Name?.Value ?? ""
};
tcNode.Format["name"] = tCol.Name?.Value ?? "";
if (tCol.Id?.Value != null) tcNode.Format["id"] = tCol.Id.Value;
if (tCol.TotalsRowFunction?.HasValue == true)
// Open XML SDK v3 EnumValue<T>.ToString() returns
// "TotalsRowFunctionValues { }" — use InnerText for the
// OOXML-canonical lowercase token. CONSISTENCY(enum-innertext).
tcNode.Format["totalFunction"] = tCol.TotalsRowFunction.InnerText;
if (tCol.TotalsRowLabel?.Value != null)View on GitHub (pinned to 1ced45e900)
Solutions
- Repair the workbook (re-save in Excel, or rebuild the table definition) so the part has a <table> element.
- Drop and re-add the table via the Add API.
- try/catch(ArgumentException) and skip the broken table.
Example fix
// before
var col = handler.Get("/Sheet1/table[1]/columns[1]"); // throws: part has no <table>
// after
try { var col = handler.Get("/Sheet1/table[1]/columns[1]"); }
catch (ArgumentException ex) when (ex.Message.Contains("no definition")) { /* table part corrupt; repair or skip */ } Defensive patterns
Strategy: try-catch
Try / catch
try { return handler.Get("/Sheet1/table[1]/columns[1]"); }
catch (ArgumentException ex) when (ex.Message.Contains("no definition")) { /* corrupt table part — repair or skip */ return null; } Prevention
- A dangling table relationship produces a part with no <table> element — re-save the workbook in Excel to repair.
- Drop and re-add the table via the Add API if the part is corrupt.
- Don't treat a missing definition as an index bug — it's a data-integrity issue.
When it happens
Trigger: handler.Get("/Sheet1/table[1]/columns[1]") when the table's definition part is present but its Table element is null — typically a hand-edited or tool-corrupted .xlsx where the table part was emptied.
Common situations: Corrupt workbook where a table relationship dangles. A write/merge tool that created the part but not the definition. A renamed/moved table whose part wasn't updated.
Related errors
- Table index {tIdx} out of range (1..{tParts.Count})
- Column index {cIdx} out of range (1..{tCols?.Count ?? 0})
- Pivot name '{explicitName}' already exists in workbook
- Table index {tableIndex} out of range (1..{tableParts.Count}
- Table {tableIndex} has no definition
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/550be0b70d378966.
Report an issue: GitHub.