Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 7 additions & 6 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
Loading