forked from p30928647/excelize
parent
43a057b1ea
commit
61d0ed1ff2
21
calc.go
21
calc.go
|
@ -6746,7 +6746,7 @@ func (fn *formulaFuncs) IF(argsList *list.List) formulaArg {
|
|||
var (
|
||||
cond bool
|
||||
err error
|
||||
result string
|
||||
result formulaArg
|
||||
)
|
||||
switch token.Type {
|
||||
case ArgString:
|
||||
|
@ -6757,13 +6757,26 @@ func (fn *formulaFuncs) IF(argsList *list.List) formulaArg {
|
|||
return newBoolFormulaArg(cond)
|
||||
}
|
||||
if cond {
|
||||
return newStringFormulaArg(argsList.Front().Next().Value.(formulaArg).String)
|
||||
value := argsList.Front().Next().Value.(formulaArg)
|
||||
switch value.Type {
|
||||
case ArgNumber:
|
||||
result = value.ToNumber()
|
||||
default:
|
||||
result = newStringFormulaArg(value.String)
|
||||
}
|
||||
return result
|
||||
}
|
||||
if argsList.Len() == 3 {
|
||||
result = argsList.Back().Value.(formulaArg).String
|
||||
value := argsList.Back().Value.(formulaArg)
|
||||
switch value.Type {
|
||||
case ArgNumber:
|
||||
result = value.ToNumber()
|
||||
default:
|
||||
result = newStringFormulaArg(value.String)
|
||||
}
|
||||
}
|
||||
}
|
||||
return newStringFormulaArg(result)
|
||||
return result
|
||||
}
|
||||
|
||||
// Lookup and Reference Functions
|
||||
|
|
|
@ -1090,6 +1090,8 @@ func TestCalcCellValue(t *testing.T) {
|
|||
`=IF(1<>1, "equal", "notequal")`: "notequal",
|
||||
`=IF("A"="A", "equal", "notequal")`: "equal",
|
||||
`=IF("A"<>"A", "equal", "notequal")`: "notequal",
|
||||
`=IF(FALSE,0,ROUND(4/2,0))`: "2",
|
||||
`=IF(TRUE,ROUND(4/2,0),0)`: "2",
|
||||
// Excel Lookup and Reference Functions
|
||||
// CHOOSE
|
||||
"=CHOOSE(4,\"red\",\"blue\",\"green\",\"brown\")": "brown",
|
||||
|
|
Loading…
Reference in New Issue