forked from p30928647/excelize
This update the return value for the `CalcCellValue` function (#1490)
- Using formula error string in the result of the `CalcCellValue` function - Using the error message in the `CalcCellValue` function returns error - Update unit tests
This commit is contained in:
parent
0d193c76ac
commit
e394f01a97
15
calc.go
15
calc.go
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1021,9 +1022,9 @@ 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
|
||||
|
@ -1031,7 +1032,7 @@ func (f *File) evalInfixExpFunc(ctx *calcContext, sheet, cell string, token, nex
|
|||
"_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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
4245
calc_test.go
4245
calc_test.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue