未验证 提交 61d0ed1f 编写于 作者: B bailantaotao 提交者: GitHub

This closes #987: support nested calc for if formula (#988)

上级 43a057b1
...@@ -6746,7 +6746,7 @@ func (fn *formulaFuncs) IF(argsList *list.List) formulaArg { ...@@ -6746,7 +6746,7 @@ func (fn *formulaFuncs) IF(argsList *list.List) formulaArg {
var ( var (
cond bool cond bool
err error err error
result string result formulaArg
) )
switch token.Type { switch token.Type {
case ArgString: case ArgString:
...@@ -6757,13 +6757,26 @@ func (fn *formulaFuncs) IF(argsList *list.List) formulaArg { ...@@ -6757,13 +6757,26 @@ func (fn *formulaFuncs) IF(argsList *list.List) formulaArg {
return newBoolFormulaArg(cond) return newBoolFormulaArg(cond)
} }
if 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 { 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 // Lookup and Reference Functions
......
...@@ -1090,6 +1090,8 @@ func TestCalcCellValue(t *testing.T) { ...@@ -1090,6 +1090,8 @@ func TestCalcCellValue(t *testing.T) {
`=IF(1<>1, "equal", "notequal")`: "notequal", `=IF(1<>1, "equal", "notequal")`: "notequal",
`=IF("A"="A", "equal", "notequal")`: "equal", `=IF("A"="A", "equal", "notequal")`: "equal",
`=IF("A"<>"A", "equal", "notequal")`: "notequal", `=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 // Excel Lookup and Reference Functions
// CHOOSE // CHOOSE
"=CHOOSE(4,\"red\",\"blue\",\"green\",\"brown\")": "brown", "=CHOOSE(4,\"red\",\"blue\",\"green\",\"brown\")": "brown",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册