{"record":{"id":"671c0e96bdcc3cbc","repo":"iOfficeAI/OfficeCLI","slug":"table-name-name-is-not-a-valid-excel-name-use","errorCode":null,"errorMessage":"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.","messagePattern":"Table 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\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs","lineNumber":58,"sourceCode":"            // 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}_'.\");\n            return name;\n        }\n        var looksLikeRef = LooksLikeCellReference(name)\n            || System.Text.RegularExpressions.Regex.IsMatch(name, @\"^[0-9]+$\");\n        return looksLikeRef ? name + \"_\" : name;\n    }\n\n    // T6 — built-in Excel table style names. Unknown names are rejected at\n    // Add time rather than silently passed through to Excel.\n    private static readonly HashSet<string> _builtInTableStyles = BuildBuiltInTableStyles();\n    private static HashSet<string> BuildBuiltInTableStyles()","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs#L40-L76","documentation":"Thrown by the table-name validator (userProvided=true) when the name fails Excel's defined-name grammar: identifier chars only (Unicode letters, digits, '.', '_'), must start with a letter or '_'. Excel accepts CJK/Cyrillic table names. Spaces, hyphens, and other punctuation pass schema validation but real Excel refuses the whole file (0x800A03EC).","triggerScenarios":"Calling an add-table API with a name containing spaces ('Sales Data'), hyphens ('Q1-Data'), leading digit ('1stTable'), or other disallowed punctuation.","commonSituations":"User-supplied table names from form fields; generating names from headers that contain spaces or symbols; copying column headers verbatim as table names.","solutions":["Strip/replace disallowed characters: spaces → '_', hyphens → '_' or remove.","Ensure the first character is a Unicode letter or '_'.","Use the validationCode regex before submitting the name."],"exampleFix":"// before\nstring name = \"Q1 Sales Data\"; // spaces → rejected\n// after\nstring name = \"Q1_Sales_Data\";\n// or sanitize programmatically:\nstring name = new string(header.Where(c => char.IsLetterOrDigit(c) || c == '_' || c == '.').ToArray());\nif (name.Length == 0 || char.IsDigit(name[0])) name = \"_\" + name;","handlingStrategy":"validation","validationCode":"// Validate against Excel's defined-name grammar\nstatic bool IsValidTableName(string name)\n    => !string.IsNullOrEmpty(name)\n       && System.Text.RegularExpressions.Regex.IsMatch(name, @\"^[\\p{L}_\\\\][\\p{L}\\p{N}._\\\\]*$\");","typeGuard":"null","tryCatchPattern":"try { /* add table */ }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"is not a valid Excel name\"))\n{ name = System.Text.RegularExpressions.Regex.Replace(name, \"[^\\\\p{L}\\\\p{N}._]\", \"_\"); if (char.IsDigit(name[0])) name = \"_\" + name; }","preventionTips":["Table names follow Excel's defined-name grammar: letters, digits, '.', '_', starting with a letter or '_'.","Sanitize header-derived names before use.","Spaces and hyphens are the most common offenders."],"tags":["tables","excel","naming","input-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}