{"record":{"id":"d3ba60d1339058de","repo":"iOfficeAI/OfficeCLI","slug":"table-name-name-matches-excel-s-internal-tbl","errorCode":null,"errorMessage":"Table name '{name}' matches Excel's internal Tbl{{N}} naming pattern and is rejected by Mac Excel. Use 'Table{{N}}' (default) or a descriptive name like 'SalesData'.","messagePattern":"Table name '(.+?)' matches Excel's internal Tbl(.+?)\\} naming pattern and is rejected by Mac Excel\\. Use 'Table(.+?)\\}' \\(default\\) or a descriptive name like 'SalesData'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs","lineNumber":47,"sourceCode":"    //\n    // When `userProvided` is false (auto-derived default such as\n    // `Table{id}`, or tableColumn name read from a header cell) we suffix\n    // \"_\" on cell-reference-shaped names to keep defaults safe.\n    internal static string SanitizeTableIdentifier(string? name, bool userProvided = false)\n    {\n        if (string.IsNullOrEmpty(name)) return \"_\";\n        if (userProvided)\n        {\n            // Mac Excel rejects the \"Tbl{N}\" pattern (Excel's internal table\n            // identifier prefix), silently renaming with a \"_\" suffix and\n            // triggering \"found a problem\" repair dialog on open. Block it\n            // up front so users get a clear error instead of the repair flow.\n            // Windows Excel auto-recovers silently which historically masked\n            // this on officeshot Windows-side validation. \"Tbl\" alone or\n            // \"Tbl\"+letters (e.g. \"TblData\") are NOT rejected — only the\n            // exact Tbl-followed-by-digits pattern collides.\n            if (System.Text.RegularExpressions.Regex.IsMatch(name, @\"^[Tt][Bb][Ll]\\d+$\"))\n                throw new ArgumentException(\n                    $\"Table name '{name}' matches Excel's internal Tbl{{N}} naming pattern and is rejected by Mac Excel. Use 'Table{{N}}' (default) or a descriptive name like 'SalesData'.\");\n            // Excel enforces defined-name grammar on table names: identifier\n            // chars only (no spaces), must not parse as an A1/R1C1 cell\n            // reference. Violations pass schema validation but real Excel\n            // refuses the whole file (0x800A03EC) — reject up front, same\n            // rule set as the namedrange validator.\n            // \"Letter\" is any Unicode letter (\\p{L}) — Excel accepts CJK/\n            // Cyrillic table names (same identifier grammar as defined\n            // names, whose validator was widened the same way).\n            if (!System.Text.RegularExpressions.Regex.IsMatch(name, @\"^[\\p{L}_\\\\][\\p{L}\\p{N}._\\\\]*$\"))\n                throw new ArgumentException(\n                    $\"Table name '{name}' is not a valid Excel name: use letters, digits, '.' or '_' only, starting with a letter or '_' (no spaces). Excel refuses to open files with other table names.\");\n            if (LooksLikeCellReference(name)\n                || System.Text.RegularExpressions.Regex.IsMatch(name, @\"^[Rr]\\d+[Cc]\\d+$\")\n                || name.Equals(\"R\", StringComparison.OrdinalIgnoreCase)\n                || name.Equals(\"C\", StringComparison.OrdinalIgnoreCase))\n                throw new ArgumentException(\n                    $\"Table name '{name}' looks like a cell reference; Excel refuses to open files with such table names. Choose a name like '{name}_'.\");","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs#L29-L65","documentation":"Thrown by the table-name validator (userProvided=true) when the name matches ^[Tt][Bb][Ll]\\d+$ — Excel's internal table identifier prefix. Mac Excel silently renames such tables with a '_' suffix and shows a 'found a problem' repair dialog on open. Windows Excel auto-recovers silently, masking the issue. The library blocks the pattern up front so users get a clear error.","triggerScenarios":"Calling an add-table API with name='Tbl1', name='tbl42', name='TBL99', or any name matching Tbl + digits. The pattern Tbl alone or Tbl+letters (e.g. 'TblData') is NOT rejected — only Tbl followed by digits.","commonSituations":"Auto-generating table names from a counter that uses 'Tbl' prefix; copying Excel's internal naming; user-chosen names that happen to match the pattern.","solutions":["Use a descriptive name like 'SalesData', or the default 'Table{N}' pattern.","Pick a prefix that is not 'Tbl' followed by digits — 'TblData', 'Table1', or any other pattern is fine.","If you must use 'Tbl', ensure it is followed by at least one letter, not digits."],"exampleFix":"// before\nstring name = $\"Tbl{n}\"; // n=1 → rejected\n// after\nstring name = $\"Table{n}\";  // 'Table1', 'Table2', ...\n// or descriptive:\nstring name = \"SalesData\";","handlingStrategy":"validation","validationCode":"// Reject the Tbl{N} pattern before the API call\nstatic bool IsReservedTblName(string name)\n    => System.Text.RegularExpressions.Regex.IsMatch(name ?? \"\", @\"^[Tt][Bb][Ll]\\d+$\");","typeGuard":"null","tryCatchPattern":"try { /* add table */ }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Tbl\"))\n{ name = name + \"Data\"; /* retry with a safe suffix */ }","preventionTips":["Never use 'Tbl' + digits as a table name — it collides with Excel's internal identifiers.","Prefer the default 'Table{N}' naming.","On Mac Excel, this pattern is the most common cause of the open-time repair dialog."],"tags":["tables","excel","naming","mac-compat"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}