{"record":{"id":"d17cd1e90764d3f3","repo":"iOfficeAI/OfficeCLI","slug":"columns-n-dxfid-requires-a-numeric-dxf-id-got","errorCode":null,"errorMessage":"columns.{n}.dxfId requires a numeric dxf id, got: '{preDxf}'","messagePattern":"columns\\.(.+?)\\.dxfId requires a numeric dxf id, got: '(.+?)'","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":1304,"sourceCode":"                }\n            }\n            else\n            {\n                for (int i = 0; i < colCount; i++)\n                    colNames[i] = $\"Column{i + 1}\";\n            }\n        }\n\n        // Validate columns.N.dxfId BEFORE creating the TableDefinitionPart.\n        // A non-numeric id used to throw further down (after AddNewPart and\n        // before Table.Save), leaving an orphan xl/tables/tableN.xml part with\n        // empty content — malformed XML that makes real Excel refuse the file.\n        for (int n = 1; n <= colCount; n++)\n        {\n            if ((properties.TryGetValue($\"columns.{n}.dxfId\", out var preDxf)\n                    || properties.TryGetValue($\"column.{n}.dxfId\", out preDxf))\n                && !uint.TryParse(preDxf, out _))\n                throw new ArgumentException(\n                    $\"columns.{n}.dxfId requires a numeric dxf id, got: '{preDxf}'\");\n        }\n\n        var tableDefPart = tblWorksheet.AddNewPart<TableDefinitionPart>();\n        var table = new Table\n        {\n            Id = (uint)tableId,\n            Name = tableName,\n            DisplayName = displayName,\n            Reference = rangeRef,\n            TotalsRowShown = hasTotalRow\n        };\n        if (hasTotalRow)\n            table.TotalsRowCount = 1;\n        if (!hasHeader)\n            table.HeaderRowCount = 0;\n\n        // An <autoFilter> is only valid on a table WITH a header row — the","sourceCodeStart":1286,"sourceCodeEnd":1322,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L1286-L1322","documentation":"Thrown by AddTable's pre-validation loop (before AddNewPart) when a columns.N.dxfId or column.N.dxfId property is present but not parseable as a uint. Validating before creating the TableDefinitionPart prevents an orphan, empty xl/tables/tableN.xml part that real Excel would refuse. The id maps to the TableColumn DataFormatId and must be a non-negative integer.","triggerScenarios":"Calling Add('/Sheet1/table', ...) with columns.1.dxfId=abc, columns.2.dxfId=-1, or column.1.dxfId= (empty).","commonSituations":"Passing a style index as a name instead of an id, a negative value, or a leftover placeholder string.","solutions":["Supply a non-negative integer dxf id that exists in the workbook's dxfs collection, e.g. columns.1.dxfId=3.","Remove the dxfId property if no custom data formatting is needed.","Use either the columns.N.dxfId or column.N.dxfId key (both are accepted)."],"exampleFix":"// before\nadd /Sheet1/table --prop columns.1.dxfId=highlight\n// after\nadd /Sheet1/table --prop columns.1.dxfId=3","handlingStrategy":"validation","validationCode":"// Validate every columns.N.dxfId / column.N.dxfId is a uint before Add.\nstatic bool TryValidateDxfIds(Dictionary<string,string> props, out string error)\n{\n    error = null;\n    foreach (var (k, v) in props)\n    {\n        if (!k.StartsWith(\"columns.\") && !k.StartsWith(\"column.\")) continue;\n        if (!k.EndsWith(\".dxfId\")) continue;\n        if (!uint.TryParse(v, out _))\n        { error = $\"{k} requires a numeric dxf id, got: '{v}'\"; return false; }\n    }\n    return true;\n}","typeGuard":"static bool IsValidDxfId(string v) => uint.TryParse(v, out _);","tryCatchPattern":"try { handler.Add(parentPath, \"table\", null, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"requires a numeric dxf id\"))\n{ /* fix or remove the offending dxfId property, then retry */ }","preventionTips":["Treat dxfId as an integer index into the workbook dxfs collection, not a style name.","Omit dxfId entirely when no per-column data formatting is needed.","Validate all columns.N.dxfId and column.N.dxfId keys together before Add."],"tags":["excel","table","validation","numeric-parsing","dxf"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}