{"record":{"id":"cc440c1f9ab22c0d","repo":"iOfficeAI/OfficeCLI","slug":"invalid-element-type-type-for-xlsx-files-belo","errorCode":null,"errorMessage":"Invalid element type '{type}' for xlsx files (belongs to {sourceFormat}). Valid values: sheet, row, cell, col, namedrange, comment, validation, autofilter, cf, databar, colorscale, iconset, formulacf, cellis, ole, picture, shape, slicer, sparkline, table, chart, pivottable.","messagePattern":"Invalid element type '(.+?)' for xlsx files \\(belongs to (.+?)\\)\\. Valid values: sheet, row, cell, col, namedrange, comment, validation, autofilter, cf, databar, colorscale, iconset, formulacf, cellis, ole, picture, shape, slicer, sparkline, table, chart, pivottable\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.cs","lineNumber":54,"sourceCode":"        // front. Without this, \"add /xlsx --type slide\" fell into AddDefault,\n        // tried to resolve the parent sheet from an empty path segment, and\n        // produced a misleading \"Sheet not found: \" error with an empty name.\n        // Naming the wrong-format type explicitly tells the caller where to\n        // look (e.g. use the .pptx variant) instead of sending them on a\n        // sheet-permission hunt.\n        var typeLower = type.ToLowerInvariant();\n        if (typeLower is \"slide\" or \"slidemaster\" or \"slidelayout\" or \"notes\"\n            or \"paragraph\" or \"p\" or \"field\"\n            or \"section\" or \"header\" or \"footer\")\n        {\n            var sourceFormat = typeLower switch\n            {\n                \"slide\" or \"slidemaster\" or \"slidelayout\" or \"notes\" => \"pptx\",\n                \"paragraph\" or \"p\" or \"field\" => \"docx/pptx\",\n                \"section\" or \"header\" or \"footer\" => \"docx\",\n                _ => \"another format\"\n            };\n            throw new ArgumentException(\n                $\"Invalid element type '{type}' for xlsx files (belongs to {sourceFormat}). \" +\n                \"Valid values: sheet, row, cell, col, namedrange, comment, validation, autofilter, \" +\n                \"cf, databar, colorscale, iconset, formulacf, cellis, ole, picture, shape, slicer, \" +\n                \"sparkline, table, chart, pivottable.\");\n        }\n\n        switch (type.ToLowerInvariant())\n        {\n            case \"sheet\":\n                return AddSheet(parentPath, type, position, properties);\n\n            case \"row\":\n                return AddRow(parentPath, type, position, properties);\n\n            case \"cell\":\n                return AddCell(parentPath, type, position, properties);\n\n            case \"namedrange\" or \"definedname\" or \"name\":","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.cs#L36-L72","documentation":"Thrown by ExcelHandler.Add's front-door format guard when the requested element type belongs to a different Office format (pptx or docx) rather than xlsx. Without this guard, e.g. 'add --type slide' would fall into AddDefault and produce a misleading 'Sheet not found:' with an empty name. The guard maps the wrong-format type to its source format and lists every valid xlsx type so the caller knows where to look.","triggerScenarios":"Calling Add on an xlsx handler with type=slide, slidemaster, slidelayout, notes (pptx); paragraph, p, field (docx/pptx); or section, header, footer (docx).","commonSituations":"Wrong handler invoked for the file type (e.g. opened a .pptx operation on an .xlsx), or a script that reuses element types across formats without branching.","solutions":["Use a valid xlsx element type: sheet, row, cell, col, namedrange, comment, validation, autofilter, cf, databar, colorscale, iconset, formulacf, cellis, ole, picture, shape, slicer, sparkline, table, chart, pivottable.","If you intended a pptx/docx element, target the corresponding pptx/docx handler instead of the xlsx one.","Double-check the file extension and handler selection in the calling code."],"exampleFix":"// before\nadd /xlsx --type slide\n// after (for xlsx)\nadd /xlsx --type sheet","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> ValidXlsxTypes = new(StringComparer.OrdinalIgnoreCase)\n{\n    \"sheet\",\"row\",\"cell\",\"col\",\"namedrange\",\"comment\",\"validation\",\"autofilter\",\n    \"cf\",\"databar\",\"colorscale\",\"iconset\",\"formulacf\",\"cellis\",\"ole\",\"picture\",\n    \"shape\",\"slicer\",\"sparkline\",\"table\",\"chart\",\"pivottable\"\n};\nstatic bool IsValidXlsxType(string type) => ValidXlsxTypes.Contains(type);","typeGuard":"static bool IsValidXlsxType(string type) => ValidXlsxTypes.Contains(type);","tryCatchPattern":"try { handler.Add(parentPath, type, null, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Invalid element type\"))\n{ /* route to the correct handler (pptx/docx) or use a valid xlsx type */ }","preventionTips":["Branch on file extension before selecting element types and handlers.","Expose the valid xlsx type list as an enum/autocomplete in any UI.","Map pptx/docx-only types to their handlers so they never reach the xlsx Add."],"tags":["excel","validation","wrong-format","element-type","dispatch"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}