INDIRECT ignores the worksheet name, loses the cell type and returns "" for "$A$1"
Description
INDIRECT splits the reference text on ":" and then calls fn.f.GetCellValue(fn.sheet, fromRef) for a single cell (calc.go:16094). Three things follow from that.
The worksheet name is never read. =INDIRECT("Data!E2") is looked up as a cell name on the current sheet, fails, and returns #REF!.
The dollar signs are not handled on that path, so =INDIRECT("$A$1") returns an empty string instead of the value of A1. That one is silent.
The single cell path returns newStringFormulaArg(value), so the result is always text. =ISNUMBER(INDIRECT("A1")) is FALSE even when A1 holds a number. That one is silent too. The range path goes through parseReference and keeps the type.
Steps to reproduce the issue
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
f.NewSheet("Data")
f.NewSheet("Sheet Two")
f.SetCellValue("Sheet1", "A1", 7)
f.SetCellValue("Data", "E2", 1)
f.SetCellValue("Sheet Two", "A1", 42)
for _, formula := range []string{
`=INDIRECT("Data!E2")`,
`=INDIRECT("Data!$E$2")`,
`=INDIRECT("'Sheet Two'!A1")`,
`=INDIRECT("Data!$E$2")+1`,
`=ISNUMBER(INDIRECT("A1"))`,
`=INDIRECT("$A$1")`,
} {
f.SetCellFormula("Sheet1", "C1", formula)
result, err := f.CalcCellValue("Sheet1", "C1")
fmt.Printf("%-30s %-10q %v\n", formula, result, err)
}
}Describe the results you received
=INDIRECT("Data!E2") "#REF!" #REF!
=INDIRECT("Data!$E$2") "#REF!" #REF!
=INDIRECT("'Sheet Two'!A1") "#REF!" #REF!
=INDIRECT("Data!$E$2")+1 "#REF!" #REF!
=ISNUMBER(INDIRECT("A1")) "FALSE" <nil>
=INDIRECT("$A$1") "" <nil>Describe the results you expected
=INDIRECT("Data!E2") "1" <nil>
=INDIRECT("Data!$E$2") "1" <nil>
=INDIRECT("'Sheet Two'!A1") "42" <nil>
=INDIRECT("Data!$E$2")+1 "2" <nil>
=ISNUMBER(INDIRECT("A1")) "TRUE" <nil>
=INDIRECT("$A$1") "7" <nil>=INDIRECT("NoSuchSheet!A1") has to stay #REF!, and =SUM(INDIRECT("Data!E1:E2")) already works, since the range path is a different one.
Go version
go version go1.26.8 linux/amd64
Excelize version or commit ID
0434413
Environment
GOOS='linux'
GOARCH='amd64'
CGO_ENABLED='1'
GOVERSION='go1.26.8'Source: qax-os/excelize