{"record":{"id":"5650cd63ff97a3fe","repo":"iOfficeAI/OfficeCLI","slug":"table-name-tablename-collides-with-the-workboo","errorCode":null,"errorMessage":"Table name '{tableName}' collides with the workbook defined name '{dnName}'. Excel requires table and defined names to be unique in one namespace; choose a different table name.","messagePattern":"Table name '(.+?)' collides with the workbook defined name '(.+?)'\\. Excel requires table and defined names to be unique in one namespace; choose a different table name\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":1126,"sourceCode":"                throw new ArgumentException(\n                    $\"Table name '{tableName}' already exists in workbook; choose a different name.\");\n            if (string.Equals(existingTable.DisplayName?.Value, displayName, StringComparison.OrdinalIgnoreCase))\n                throw new ArgumentException(\n                    $\"Table displayName '{displayName}' already exists in workbook; choose a different displayName.\");\n        }\n        // Excel's name uniqueness spans ListObjects AND workbook defined\n        // names in one namespace — a collision passes schema validation but\n        // real Excel refuses the file (0x800A03EC).\n        var definedNames = _doc.WorkbookPart.Workbook?.DefinedNames;\n        if (definedNames != null)\n        {\n            foreach (var dn in definedNames.Elements<DefinedName>())\n            {\n                var dnName = dn.Name?.Value;\n                if (dnName != null\n                    && (string.Equals(dnName, tableName, StringComparison.OrdinalIgnoreCase)\n                        || string.Equals(dnName, displayName, StringComparison.OrdinalIgnoreCase)))\n                    throw new ArgumentException(\n                        $\"Table name '{tableName}' collides with the workbook defined name '{dnName}'. Excel requires table and defined names to be unique in one namespace; choose a different table name.\");\n            }\n        }\n        var styleName = properties.GetValueOrDefault(\"style\", \"TableStyleMedium2\");\n        // BUG-R9-B2: accept short aliases (medium2, light1, dark1, none) — schema\n        // documents these but ValidateTableStyleName only accepted full names.\n        styleName = NormalizeTableStyleName(styleName) ?? styleName;\n        // T6 — validate style name against the built-in whitelist +\n        // any workbook-level customStyles. Unknown names silently\n        // fell through to Excel which would either ignore or\n        // reject the file; prefer an explicit ArgumentException.\n        ValidateTableStyleName(styleName);\n        // T1 — accept `showHeader=false` alias alongside `headerRow=false`.\n        var hasHeader = !(properties.TryGetValue(\"headerRow\", out var hrVal) && !IsTruthy(hrVal))\n                     && !(properties.TryGetValue(\"showHeader\", out var shVal) && !IsTruthy(shVal));\n        // CONSISTENCY(table-totalrow): accept `showTotals=true` alias\n        // alongside `totalRow=true` (mirrors the `showHeader` alias\n        // pattern above for users coming from Office API vocabulary).","sourceCodeStart":1108,"sourceCodeEnd":1144,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L1108-L1144","documentation":"Thrown by AddTable when the new table's Name or DisplayName collides with a workbook-level DefinedName. Excel places ListObjects and defined names in one namespace; although the collision passes OOXML schema validation, real Excel refuses the file with error 0x800A03EC. The handler iterates the workbook's DefinedNames and rejects any case-insensitive match up front.","triggerScenarios":"Adding a table named 'SalesData' when a workbook defined name 'SalesData' already exists, or any name collision between the table Name/DisplayName and a DefinedName.","commonSituations":"Importing data that creates a defined name, then adding a table with the same label; or auto-generating table names that happen to match existing named ranges.","solutions":["Choose a table name that does not match any existing defined name.","Rename or remove the conflicting defined name first.","Query the workbook's defined names before adding the table to pick a free name."],"exampleFix":"// before (defined name 'SalesData' exists)\nadd /Sheet1/table --prop name=SalesData --prop ref=A1:D10\n// after\nadd /Sheet1/table --prop name=SalesTable --prop ref=A1:D10","handlingStrategy":"validation","validationCode":"// Check candidate table name against workbook defined names before Add.\nstatic bool CollidesWithDefinedName(ExcelHandler h, string candidate)\n{\n    foreach (var dn in h.ListDefinedNames()) // pseudo\n        if (string.Equals(dn, candidate, StringComparison.OrdinalIgnoreCase))\n            return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try { handler.Add(parentPath, \"table\", null, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"collides with the workbook defined name\"))\n{ /* rename the table or the defined name, then retry */ }","preventionTips":["Treat defined names and table names as one namespace in your naming logic.","Query defined names before generating table names.","Avoid generic labels like 'Data' that commonly collide with named ranges."],"tags":["excel","table","validation","naming","defined-names","namespace-collision"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}