{"record":{"id":"1ba5a9ecd3371782","repo":"qax-os/excelize","slug":"value","errorCode":"#VALUE!","errorMessage":"#VALUE!","messagePattern":"#VALUE!","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"calc.go","lineNumber":1244,"sourceCode":"\t\t\targument = false\n\t\t}\n\t\t// Restore saved tokens\n\t\tfor i := len(savedTokens) - 1; i >= 0; i-- {\n\t\t\topftStack.Push(savedTokens[i])\n\t\t}\n\t\topftStack.Push(topOpt)\n\t}\n\t// push opfd to args\n\tif argument && opfdStack.Len() > 0 {\n\t\targsStack.Peek().(*list.List).PushBack(opfdStack.Pop().(formulaArg))\n\t}\n}\n\n// calcPow evaluate exponentiation arithmetic operations.\nfunc calcPow(rOpd, lOpd formulaArg, opdStack *Stack) error {\n\tlOpdVal := lOpd.ToNumber()\n\tif lOpdVal.Type != ArgNumber {\n\t\treturn errors.New(lOpdVal.String)\n\t}\n\trOpdVal := rOpd.ToNumber()\n\tif rOpdVal.Type != ArgNumber {\n\t\treturn errors.New(rOpdVal.String)\n\t}\n\topdStack.Push(newNumberFormulaArg(math.Pow(lOpdVal.Number, rOpdVal.Number)))\n\treturn nil\n}\n\n// calcEq evaluate equal arithmetic operations.\nfunc calcEq(rOpd, lOpd formulaArg, opdStack *Stack) error {\n\tif rOpd.Type == ArgString && lOpd.Type == ArgString {\n\t\topdStack.Push(newBoolFormulaArg(strings.EqualFold(lOpd.Value(), rOpd.Value())))\n\t\treturn nil\n\t}\n\topdStack.Push(newBoolFormulaArg(rOpd.Value() == lOpd.Value()))\n\treturn nil\n}","sourceCodeStart":1226,"sourceCodeEnd":1262,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/calc.go#L1226-L1262","documentation":"calcPow implements the '^' (exponentiation) operator. Before multiplying it converts both operands with formulaArg.ToNumber(); if a conversion fails (e.g. a non-numeric string operand, which ToNumber turns into a #VALUE! error arg), it returns that error and the engine yields #VALUE! for the cell. Numeric strings like \"3\" convert fine; text like \"abc\" does not.","triggerScenarios":"A formula like \"=A1^B1\" or \"=2^A1\" where A1/B1 hold text that cannot be parsed as a float (calc.go:1244 checks the left operand's ToNumber result).","commonSituations":"Cells imported from CSV where numbers were saved as text; cells containing units or whitespace-padded non-numeric strings; formula referencing an empty-formatted text cell or a label like 'N/A'.","solutions":["Fix the referenced cell to contain a numeric value (or a numeric string).","Wrap the operand in VALUE(), e.g. \"=VALUE(A1)^2\", so text-numbers convert and true text is handled explicitly.","Clean the source data: strip whitespace/units before writing, or write numbers with SetCellValue's typed methods instead of strings.","Pre-check the operand cells in Go before calling CalcCellValue."],"exampleFix":"// before: A1 = \"abc\" and formula \"=A1^2\" -> \"#VALUE!\"\nf.SetCellFormula(\"Sheet1\", \"B1\", \"=A1^2\")\n// after: coerce or guard the operand\nf.SetCellFormula(\"Sheet1\", \"B1\", \"=IF(ISNUMBER(A1),A1^2,0)\")","handlingStrategy":"validation","validationCode":"func isNumericCell(f *excelize.File, sheet, cell string) bool {\n\tv, err := f.GetCellValue(sheet, cell)\n\tif err != nil || v == \"\" {\n\t\treturn false\n\t}\n\t_, err = strconv.ParseFloat(strings.TrimSpace(v), 64)\n\treturn err == nil\n}\n// check isNumericCell(f, \"Sheet1\", \"A1\") before relying on \"=A1^2\"","typeGuard":"func isNumber(v string) bool {\n\t_, err := strconv.ParseFloat(strings.TrimSpace(v), 64)\n\treturn err == nil\n}","tryCatchPattern":"val, err := f.CalcCellValue(\"Sheet1\", \"B1\")\nif err != nil || val == \"#VALUE!\" {\n\t// operand was non-numeric; apply a default or surface a data-quality warning\n\tval = \"0\"\n}","preventionTips":["Write numeric data with SetCellValue typed values, never as decorated strings.","Strip units, currency symbols, and whitespace from numbers at import time.","Normalize locale decimal separators to '.' before storing numbers.","Wrap risky operands in ISNUMBER guards inside formulas."],"tags":["formula","excel","type-conversion","go"],"backgroundTag":"formula-value-error","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}