{"record":{"id":"57aed09a8e695c64","repo":"iOfficeAI/OfficeCLI","slug":"unknown-table-style-stylename-use-a-built-in","errorCode":null,"errorMessage":"Unknown table style: '{styleName}'. Use a built-in name like 'TableStyleMedium2', or register a custom style on the workbook first.","messagePattern":"Unknown table style: '(.+?)'\\. Use a built-in name like 'TableStyleMedium2', or register a custom style on the workbook first\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs","lineNumber":128,"sourceCode":"                       m.Groups[1].Value.Substring(1).ToLowerInvariant();\n            return $\"TableStyle{tier}{n}\";\n        }\n        return styleName;\n    }\n\n    internal void ValidateTableStyleName(string? styleName)\n    {\n        if (string.IsNullOrEmpty(styleName)) return;\n        if (_builtInTableStyles.Contains(styleName)) return;\n        // Workbook-level customStyles live under <x:tableStyles> on the stylesheet.\n        var styles = _doc.WorkbookPart?.WorkbookStylesPart?.Stylesheet;\n        var tableStyles = styles?.GetFirstChild<TableStyles>();\n        if (tableStyles != null)\n        {\n            foreach (var ts in tableStyles.Elements<TableStyle>())\n                if (ts.Name?.Value == styleName) return;\n        }\n        throw new ArgumentException(\n            $\"Unknown table style: '{styleName}'. Use a built-in name like \" +\n            $\"'TableStyleMedium2', or register a custom style on the workbook first.\");\n    }\n}\n","sourceCodeStart":110,"sourceCodeEnd":133,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.TableStyle.cs#L110-L133","documentation":"Thrown by ValidateTableStyleName when the requested style is not a built-in Excel table/pivot style (TableStyleLight1..28, TableStyleMedium1..28, TableStyleDark1..28, PivotStyle*, TableStyleNone) and is not registered as a custom table style under <x:tableStyles> on the workbook's stylesheet. The library rejects unknown names at add-time rather than letting Excel fail later.","triggerScenarios":"Calling an add-table or style API with styleName='MyCustomStyle' when that style is not defined in the workbook; a typo like 'TableStyleMeduim2'; a short alias that was not normalized first (the validator expects the full 'TableStyleX' form unless NormalizeTableStyleName is called beforehand).","commonSituations":"Typos in built-in names; referencing a custom style that was never registered; using a short alias ('medium2') without running it through NormalizeTableStyleName first.","solutions":["For built-in styles, use the full canonical name (e.g. 'TableStyleMedium2') or run NormalizeTableStyleName first to expand short aliases.","For custom styles, register the style under <x:tableStyles> on the stylesheet before referencing it.","Check the built-in list (Light/Medium/Dark tiers, 1..28) for typos."],"exampleFix":"// before\nstring style = \"medium2\"; // short alias, not accepted directly\n// after\nstring style = \"TableStyleMedium2\"; // full canonical name\n// or normalize first:\nstring style = NormalizeTableStyleName(\"medium2\"); // → \"TableStyleMedium2\"","handlingStrategy":"validation","validationCode":"// Validate a style name before use\nstatic readonly HashSet<string> BuiltIns = BuildBuiltInTableStyles();\nstatic bool IsKnownStyle(SpreadsheetDocument doc, string style)\n{\n    if (BuiltIns.Contains(style)) return true;\n    var ts = doc?.WorkbookPart?.WorkbookStylesPart?.Stylesheet?.GetFirstChild<TableStyles>();\n    return ts?.Elements<TableStyle>().Any(t => t.Name?.Value == style) == true;\n}","typeGuard":"null","tryCatchPattern":"try { ValidateTableStyleName(style); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Unknown table style\"))\n{ style = NormalizeTableStyleName(style) ?? \"TableStyleMedium2\"; /* fall back to a built-in */ }","preventionTips":["Built-in style names are the full 'TableStyle{tier}{1..28}' form — short aliases need NormalizeTableStyleName first.","Register custom styles before referencing them.","The validator is case-sensitive on built-in names."],"tags":["tables","excel","styling","input-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}