qax-os/excelize · error

#VALUE!

#VALUE!

Error message

#VALUE!

What it means

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.

Source

Thrown at calc.go:1244

			argument = false
		}
		// Restore saved tokens
		for i := len(savedTokens) - 1; i >= 0; i-- {
			opftStack.Push(savedTokens[i])
		}
		opftStack.Push(topOpt)
	}
	// push opfd to args
	if argument && opfdStack.Len() > 0 {
		argsStack.Peek().(*list.List).PushBack(opfdStack.Pop().(formulaArg))
	}
}

// calcPow evaluate exponentiation arithmetic operations.
func calcPow(rOpd, lOpd formulaArg, opdStack *Stack) error {
	lOpdVal := lOpd.ToNumber()
	if lOpdVal.Type != ArgNumber {
		return errors.New(lOpdVal.String)
	}
	rOpdVal := rOpd.ToNumber()
	if rOpdVal.Type != ArgNumber {
		return errors.New(rOpdVal.String)
	}
	opdStack.Push(newNumberFormulaArg(math.Pow(lOpdVal.Number, rOpdVal.Number)))
	return nil
}

// calcEq evaluate equal arithmetic operations.
func calcEq(rOpd, lOpd formulaArg, opdStack *Stack) error {
	if rOpd.Type == ArgString && lOpd.Type == ArgString {
		opdStack.Push(newBoolFormulaArg(strings.EqualFold(lOpd.Value(), rOpd.Value())))
		return nil
	}
	opdStack.Push(newBoolFormulaArg(rOpd.Value() == lOpd.Value()))
	return nil
}

View on GitHub (pinned to f2483381fb)

Solutions

  1. Fix the referenced cell to contain a numeric value (or a numeric string).
  2. Wrap the operand in VALUE(), e.g. "=VALUE(A1)^2", so text-numbers convert and true text is handled explicitly.
  3. Clean the source data: strip whitespace/units before writing, or write numbers with SetCellValue's typed methods instead of strings.
  4. Pre-check the operand cells in Go before calling CalcCellValue.

Example fix

// before: A1 = "abc" and formula "=A1^2" -> "#VALUE!"
f.SetCellFormula("Sheet1", "B1", "=A1^2")
// after: coerce or guard the operand
f.SetCellFormula("Sheet1", "B1", "=IF(ISNUMBER(A1),A1^2,0)")
Defensive patterns

Strategy: validation

Validate before calling

func isNumericCell(f *excelize.File, sheet, cell string) bool {
	v, err := f.GetCellValue(sheet, cell)
	if err != nil || v == "" {
		return false
	}
	_, err = strconv.ParseFloat(strings.TrimSpace(v), 64)
	return err == nil
}
// check isNumericCell(f, "Sheet1", "A1") before relying on "=A1^2"

Type guard

func isNumber(v string) bool {
	_, err := strconv.ParseFloat(strings.TrimSpace(v), 64)
	return err == nil
}

Try / catch

val, err := f.CalcCellValue("Sheet1", "B1")
if err != nil || val == "#VALUE!" {
	// operand was non-numeric; apply a default or surface a data-quality warning
	val = "0"
}

Prevention

When it happens

Trigger: 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).

Common situations: 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'.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/1ba5a9ecd3371782. Report an issue: GitHub.