#2432·excelize

The minus operator treats an error operand as zero

Author: zac-scheiweCreated Sep 27, 2026Updated Sep 27, 2026

Description

In Excel, a - b is an error whenever a or b is an error. In Excelize, if a or b is an error, - treats it as zero. So 1/0 - 1 evaluates to -1.

Steps to reproduce the issue

go
package main

import (
      "fmt"

      "github.com/xuri/excelize/v2"
)

func main() {
      f := excelize.NewFile()
      f.SetCellValue("Sheet1", "A1", "abc")
      for _, formula := range []string{
              "=1/0-1",
              "=1-(1/0)",
              "=-(1/0)",
              "=-A1",
              "=IFERROR(1-(1/0),3)",
      } {
              f.SetCellFormula("Sheet1", "C1", formu
              result, err := f.CalcCellValue("Sheet1", "C1")
              fmt.Printf("%-20s %-10q %v\n", formula
      }
}

Describe the results you received

=1/0-1               "-1"       <nil>
=1-(1/0)             "1"        <nil>
=-(1/0)              "0"        <nil>
=-A1                 "0"        <nil>
=IFERROR(1-(1/0),3)  "1"        <nil>

Describe the results you expected

=1/0-1               "#DIV/0!"  #DIV/0!
=1-(1/0)             "#DIV/0!"  #DIV/0!
=-(1/0)              "#DIV/0!"  #DIV/0!
=-A1                 "#VALUE!"  #VALUE!
=IFERROR(1-(1/0),3)  "3"        <nil>

Go version

1.27.1

Excelize version or commit ID

2.11.0

Environment

bash
macOS darwin/arm64
Microsoft Excel for Mac 16.113.2 (build 16.113.26092012)

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.