{"record":{"id":"f8b96002a8a0757b","repo":"iOfficeAI/OfficeCLI","slug":"table-tableindex-has-no-definition","errorCode":null,"errorMessage":"Table {tableIndex} has no definition","messagePattern":"Table (.+?) has no definition","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Node.cs","lineNumber":1040,"sourceCode":"            var fontStr = o[\"font\"]?.GetValue<string>();\n            rPr.AppendChild(new RunFont { Val = string.IsNullOrWhiteSpace(fontStr) ? \"Tahoma\" : fontStr });\n\n            ct.AppendChild(new Run(rPr,\n                new Text(text.Replace(\"\\r\\n\", \"\\n\")) { Space = SpaceProcessingModeValues.Preserve }));\n        }\n        return ct;\n    }\n\n    // ==================== Data Validation Helpers ====================\n\n    private DocumentNode TableToNode(string sheetName, WorksheetPart worksheetPart, int tableIndex, int depth)\n    {\n        var tableParts = worksheetPart.TableDefinitionParts.ToList();\n        if (tableIndex < 1 || tableIndex > tableParts.Count)\n            throw new ArgumentException($\"Table index {tableIndex} out of range (1..{tableParts.Count})\");\n\n        var tbl = tableParts[tableIndex - 1].Table\n            ?? throw new ArgumentException($\"Table {tableIndex} has no definition\");\n\n        var node = new DocumentNode\n        {\n            Path = $\"/{sheetName}/table[{tableIndex}]\",\n            Type = \"table\",\n            Text = tbl.DisplayName?.Value ?? tbl.Name?.Value ?? $\"Table{tableIndex}\",\n            Preview = $\"{tbl.Name?.Value} ({tbl.Reference?.Value})\"\n        };\n\n        node.Format[\"name\"] = tbl.Name?.Value ?? \"\";\n        node.Format[\"displayName\"] = tbl.DisplayName?.Value ?? \"\";\n        node.Format[\"ref\"] = tbl.Reference?.Value ?? \"\";\n\n        var styleInfo = tbl.GetFirstChild<TableStyleInfo>();\n        if (styleInfo?.Name?.Value != null)\n            node.Format[\"style\"] = styleInfo.Name.Value;\n        if (styleInfo != null)\n        {","sourceCodeStart":1022,"sourceCodeEnd":1058,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Node.cs#L1022-L1058","documentation":"Thrown by TableToNode when the TableDefinitionPart at the requested index has a null .Table property — the part exists in the package but its underlying definition element is missing. Indicates a malformed/corrupt OOXML package rather than a wrong index.","triggerScenarios":"Loading an .xlsx where a table part was left in the package but its table1.xml is empty or missing the <table> root; hand-edited packages that broke a relationship target; partial-write corruption.","commonSituations":"Files produced by a buggy generator that wrote the relationship but not the part content; zip manipulation that dropped a part after adding its rels; round-trip through a tool that strips tables.","solutions":["Open the file in Excel and let it repair, then re-save — this restores the missing definition.","Regenerate the file from the source of truth if it is programmatically produced.","Inspect xl/worksheets/_rels/*.rels and the target tableN.xml to find the broken relationship."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// Cannot pre-validate without re-implementing the loader; treat as load-time risk\nstatic bool TryGetTable(WorksheetPart wsp, int idx, out Table tbl)\n{\n    tbl = null;\n    var parts = wsp.TableDefinitionParts.ToList();\n    if (idx < 1 || idx > parts.Count) return false;\n    tbl = parts[idx - 1].Table;\n    return tbl != null;\n}","typeGuard":"null","tryCatchPattern":"try { TableToNode(...); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"has no definition\"))\n{ // log corrupt-file path; do not retry on the same file\n  File.Copy(path, path + \".corrupt\", overwrite: true); }","preventionTips":["Treat 'has no definition' as file corruption, not a caller bug.","Validate files after generation by reopening them.","Keep source data so a corrupt file can be regenerated."],"tags":["tables","excel","corrupt-file","ooxml"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}