{"record":{"id":"f4ec2ee57f33024b","repo":"iOfficeAI/OfficeCLI","slug":"invalid-cell-type-value-celltype-valid-type","errorCode":null,"errorMessage":"Invalid cell 'type' value '{cellType}'. Valid types: string, number, boolean, date, error, richtext.","messagePattern":"Invalid cell 'type' value '(.+?)'\\. Valid types: string, number, boolean, date, error, richtext\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Cells.cs","lineNumber":692,"sourceCode":"                        $\"Cannot store '{cell.CellValue?.Text}' as boolean; value must be true/false, yes/no, or 1/0. \" +\n                        \"Use type=string to keep the literal text.\");\n                cell.DataType = cellType.ToLowerInvariant() switch\n                {\n                    \"string\" or \"str\" => new EnumValue<CellValues>(CellValues.String),\n                    \"number\" or \"num\" => null,\n                    \"boolean\" or \"bool\" => new EnumValue<CellValues>(CellValues.Boolean),\n                    // CONSISTENCY(cell-type-parity): Bug #4 — Add must accept\n                    // the same type tokens as Set (ExcelHandler.Set.cs line 1105).\n                    // Dates are stored as numeric OADate, so DataType stays null;\n                    // the date-shaped cell value serialization and default\n                    // numberformat are applied right after this switch.\n                    \"date\" => null,\n                    // CE16 — accept `type=error value=\"#N/A\"|\"#DIV/0!\"|...` →\n                    // emits <x:c t=\"e\"><x:v>#N/A</x:v></x:c>. Standard\n                    // Excel error tokens: #N/A, #DIV/0!, #REF!, #NAME?,\n                    // #NULL!, #NUM!, #VALUE!, #GETTING_DATA.\n                    \"error\" or \"err\" => new EnumValue<CellValues>(CellValues.Error),\n                    _ => throw new ArgumentException($\"Invalid cell 'type' value '{cellType}'. Valid types: string, number, boolean, date, error, richtext.\")\n                };\n                // Convert boolean string values to OOXML-compliant 1/0\n                if (cellType.Equals(\"boolean\", StringComparison.OrdinalIgnoreCase) || cellType.Equals(\"bool\", StringComparison.OrdinalIgnoreCase))\n                {\n                    var boolText = cell.CellValue?.Text?.Trim().ToLowerInvariant();\n                    if (boolText == \"true\" || boolText == \"yes\" || boolText == \"1\")\n                        cell.CellValue = new CellValue(\"1\");\n                    else if (boolText == \"false\" || boolText == \"no\" || boolText == \"0\")\n                        cell.CellValue = new CellValue(\"0\");\n                    else if (!string.IsNullOrEmpty(boolText))\n                        // A t=\"b\" cell whose value isn't 0/1 makes real Excel\n                        // refuse the whole file (0x800A03EC). Reject up front,\n                        // mirroring the type=date guard.\n                        throw new ArgumentException(\n                            $\"Cannot store '{cell.CellValue?.Text}' as boolean; value must be true/false, yes/no, or 1/0. \" +\n                            \"Use type=string to keep the literal text.\");\n                }\n                // A type=number cell stores its value in <v> with no t=","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Cells.cs#L674-L710","documentation":"The cell type switch accepts a fixed token set: string/str, number/num, boolean/bool, date, error/err, and richtext/rich. The switch's default arm throws for any unrecognized type token, mirroring Set's accepted tokens (CONSISTENCY(cell-type-parity)) so Add and Set accept the same vocabulary.","triggerScenarios":"Add(\"/Sheet1/A1\",\"cell\",pos,{[\"type\"]=\"int\"}); type=\"text\" (use 'string' or 'str'); type=\"float\" (use 'number' or 'num'); type=\"datetime\" (use 'date'); type=\"bool2\".","commonSituations":"Using language-native type names (int, float, text) instead of the OOXML-oriented token set; expecting 'datetime' when only 'date' is accepted; a typo in the type token.","solutions":["Use one of the accepted tokens: string (or str), number (or num), boolean (or bool), date, error (or err), richtext (or rich).","For free text use string/str; for numbers use number/num; for error literals use error with value=#N/A etc.","Rich text is a separate branch (type=richtext/rich triggers ApplyRichTextToCell) and is not part of this switch's default error."],"exampleFix":"// before\nhandler.Add(\"/Sheet1/A1\", \"cell\", null, new() { [\"type\"] = \"text\", [\"value\"] = \"x\" });\n// after\nhandler.Add(\"/Sheet1/A1\", \"cell\", null, new() { [\"type\"] = \"string\", [\"value\"] = \"x\" });","handlingStrategy":"type-guard","validationCode":"static readonly HashSet<string> CellTypes = new(StringComparer.OrdinalIgnoreCase)\n{\"string\",\"str\",\"number\",\"num\",\"boolean\",\"bool\",\"date\",\"error\",\"err\",\"richtext\",\"rich\"};\nif (props.TryGetValue(\"type\", out var t) && !CellTypes.Contains(t))\n    throw new ArgumentException($\"Unsupported cell type: {t}\");\nh.Add(parentPath, \"cell\", pos, props);","typeGuard":"static bool IsValidCellType(string? t) =>\n    t?.ToLowerInvariant() is \"string\" or \"str\" or \"number\" or \"num\" or \"boolean\" or \"bool\"\n    or \"date\" or \"error\" or \"err\" or \"richtext\" or \"rich\";","tryCatchPattern":"try { h.Add(parentPath, \"cell\", pos, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid cell 'type' value\"))\n{ /* map to the accepted token set, e.g. text->string, int->number */ }","preventionTips":["Use the OOXML-oriented token set, not language-native names (int/float/text).","Validate the type token against the accepted set before the call.","Remember 'date' covers datetime; 'datetime' is not accepted."],"tags":["excel","xlsx","cell","type","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}