This closes #1164, fix nested formula calculation result error

This commit is contained in:
xuri 2022-03-04 00:44:50 +08:00
parent 3971e8a48b
commit 129052ae7d
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 12 additions and 0 deletions

11
calc.go
View File

@ -809,6 +809,17 @@ func (f *File) evalInfixExp(sheet, cell string, tokens []efp.Token) (efp.Token,
}
}
if isEndParenthesesToken(token) && isBeginParenthesesToken(opftStack.Peek().(efp.Token)) {
if arg := argsStack.Peek().(*list.List).Back(); arg != nil {
opfdStack.Push(efp.Token{
TType: efp.TokenTypeOperand,
TSubType: efp.TokenSubTypeNumber,
TValue: arg.Value.(formulaArg).Value(),
})
argsStack.Peek().(*list.List).Remove(arg)
}
}
// check current token is opft
if err = f.parseToken(sheet, token, opfdStack, opftStack); err != nil {
return efp.Token{}, err

View File

@ -725,6 +725,7 @@ func TestCalcCellValue(t *testing.T) {
"=1+SUM(SUM(1,2*3),4)*-4/2+5+(4+2)*3": "2",
"=1+SUM(SUM(1,2*3),4)*4/3+5+(4+2)*3": "38.666666666666664",
"=SUM(1+ROW())": "2",
"=SUM((SUM(2))+1)": "3",
// SUMIF
`=SUMIF(F1:F5, "")`: "0",
`=SUMIF(A1:A5, "3")`: "3",