Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NA error #1490

Merged
merged 3 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ func (f *File) CalcCellValue(sheet, cell string, opts ...Options) (result string
iterations: make(map[string]uint),
iterationsCache: make(map[string]formulaArg),
}, sheet, cell); err != nil {
result = token.String
return
}
if !rawCellValue {
Expand Down Expand Up @@ -1002,8 +1003,8 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T
inArray = false
continue
}
if err = f.evalInfixExpFunc(ctx, sheet, cell, token, nextToken, opfStack, opdStack, opftStack, opfdStack, argsStack); err != nil {
return newEmptyFormulaArg(), err
if errArg := f.evalInfixExpFunc(ctx, sheet, cell, token, nextToken, opfStack, opdStack, opftStack, opfdStack, argsStack); errArg.Type == ArgError {
return errArg, errors.New(errArg.Error)
}
}
}
Expand All @@ -1021,17 +1022,17 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T
}

// evalInfixExpFunc evaluate formula function in the infix expression.
func (f *File) evalInfixExpFunc(ctx *calcContext, sheet, cell string, token, nextToken efp.Token, opfStack, opdStack, opftStack, opfdStack, argsStack *Stack) error {
func (f *File) evalInfixExpFunc(ctx *calcContext, sheet, cell string, token, nextToken efp.Token, opfStack, opdStack, opftStack, opfdStack, argsStack *Stack) formulaArg {
if !isFunctionStopToken(token) {
return nil
return newEmptyFormulaArg()
}
prepareEvalInfixExp(opfStack, opftStack, opfdStack, argsStack)
// call formula function to evaluate
arg := callFuncByName(&formulaFuncs{f: f, sheet: sheet, cell: cell, ctx: ctx}, strings.NewReplacer(
"_xlfn.", "", ".", "dot").Replace(opfStack.Peek().(efp.Token).TValue),
[]reflect.Value{reflect.ValueOf(argsStack.Peek().(*list.List))})
if arg.Type == ArgError && opfStack.Len() == 1 {
return errors.New(arg.Value())
return arg
}
argsStack.Pop()
opftStack.Pop() // remove current function separator
Expand All @@ -1050,7 +1051,7 @@ func (f *File) evalInfixExpFunc(ctx *calcContext, sheet, cell string, token, nex
}
opdStack.Push(newStringFormulaArg(val))
}
return nil
return newEmptyFormulaArg()
}

// prepareEvalInfixExp check the token and stack state for formula function
Expand Down Expand Up @@ -11612,7 +11613,7 @@ func (fn *formulaFuncs) IFNA(argsList *list.List) formulaArg {
return newErrorFormulaArg(formulaErrorVALUE, "IFNA requires 2 arguments")
}
arg := argsList.Front().Value.(formulaArg)
if arg.Type == ArgError && arg.Value() == formulaErrorNA {
if arg.Type == ArgError && arg.String == formulaErrorNA {
return argsList.Back().Value.(formulaArg)
}
return arg
Expand Down
Loading