{"record":{"id":"194859b907fe3b43","repo":"iOfficeAI/OfficeCLI","slug":"table-displayname-displayname-already-exists-i","errorCode":null,"errorMessage":"Table displayName '{displayName}' already exists in workbook; choose a different displayName.","messagePattern":"Table displayName '(.+?)' already exists in workbook; choose a different displayName\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":1111,"sourceCode":"        var userProvidedDisplay = properties.ContainsKey(\"displayName\");\n        var displayName = SanitizeTableIdentifier(\n            properties.GetValueOrDefault(\"displayName\", tableName),\n            userProvided: userProvidedDisplay || userProvidedName);\n\n        // CONSISTENCY(table-name-unique): Excel requires both name and\n        // displayName to be unique workbook-wide. A duplicate across\n        // sheets surfaces a \"found a problem\" repair dialog. Walk every\n        // WorksheetPart's tables, comparing case-insensitively.\n        foreach (var existingTable in _doc.WorkbookPart!.WorksheetParts\n            .SelectMany(wp => wp.TableDefinitionParts)\n            .Select(tdp => tdp.Table)\n            .Where(t => t != null)!)\n        {\n            if (string.Equals(existingTable!.Name?.Value, tableName, StringComparison.OrdinalIgnoreCase))\n                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        }","sourceCodeStart":1093,"sourceCodeEnd":1129,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L1093-L1129","documentation":"Thrown by AddTable's workbook-wide uniqueness check when a table with the same DisplayName (case-insensitive) already exists on any sheet. DisplayName (the ListObject name Excel shows in the UI and formula references) must be unique across the workbook alongside Name; a duplicate triggers a repair dialog. The check compares case-insensitively against every existing table's DisplayName.","triggerScenarios":"Adding a table whose computed or supplied DisplayName matches an existing table's DisplayName, e.g. when displayName collides because the name-derived display name was already taken.","commonSituations":"Two tables whose Name differs but whose DisplayName resolves to the same value, or explicitly setting a duplicate displayName property.","solutions":["Provide an explicit, unique displayName property.","Remove or rename the conflicting existing table.","Omit displayName so the handler derives it from a unique name."],"exampleFix":"// before\nadd /Sheet2/table --prop name=Sales2 --prop displayName=Sales --prop ref=A1:D10\n// after\nadd /Sheet2/table --prop name=Sales2 --prop displayName=Sales2 --prop ref=A1:D10","handlingStrategy":"validation","validationCode":"// Reserve a workbook-unique displayName before Add (mirrors the 586 name check).\nstatic string UniqueDisplayName(ExcelHandler h, string baseDisplay)\n{\n    var taken = new HashSet<string>(h.ListTableDisplayNames(), StringComparer.OrdinalIgnoreCase); // pseudo\n    var d = baseDisplay; int i = 2;\n    while (taken.Contains(d)) d = $\"{baseDisplay}{i++}\";\n    return d;\n}","typeGuard":null,"tryCatchPattern":"try { handler.Add(parentPath, \"table\", null, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"displayName\") && ex.Message.Contains(\"already exists\"))\n{ /* supply a unique displayName and retry */ }","preventionTips":["Track displayNames separately from names; both must be workbook-unique.","When deriving displayName from name, ensure the derivation cannot collide.","Omit displayName to let the handler derive it from a unique name."],"tags":["excel","table","validation","naming","uniqueness"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}