diff options
author | xuri <xuri.me@gmail.com> | 2020-06-04 00:35:54 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2020-06-04 00:35:54 +0800 |
commit | b6dd7648a142901655cc4f76cb7d3a6e73338c8f (patch) | |
tree | 41b6d815a5f0b9129dd146c7203d8d1714bff882 /calc.go | |
parent | b62950a39ef2063ec19c221a32d37bd01f197472 (diff) |
fn: COUNTA
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 34 |
1 files changed, 31 insertions, 3 deletions
@@ -313,7 +313,7 @@ func calcAdd(opdStack *Stack) error { return nil } -// calcAdd evaluate subtraction arithmetic operations. +// calcSubtract evaluate subtraction arithmetic operations. func calcSubtract(opdStack *Stack) error { if opdStack.Len() < 2 { return errors.New("formula not valid") @@ -333,7 +333,7 @@ func calcSubtract(opdStack *Stack) error { return nil } -// calcAdd evaluate multiplication arithmetic operations. +// calcMultiply evaluate multiplication arithmetic operations. func calcMultiply(opdStack *Stack) error { if opdStack.Len() < 2 { return errors.New("formula not valid") @@ -353,7 +353,7 @@ func calcMultiply(opdStack *Stack) error { return nil } -// calcAdd evaluate division arithmetic operations. +// calcDivide evaluate division arithmetic operations. func calcDivide(opdStack *Stack) error { if opdStack.Len() < 2 { return errors.New("formula not valid") @@ -2840,6 +2840,34 @@ func (fn *formulaFuncs) TRUNC(argsList *list.List) (result string, err error) { // Statistical functions +// COUNTA function returns the number of non-blanks within a supplied set of +// cells or values. The syntax of the function is: +// +// COUNTA(value1,[value2],...) +// +func (fn *formulaFuncs) COUNTA(argsList *list.List) (result string, err error) { + var count int + for token := argsList.Front(); token != nil; token = token.Next() { + arg := token.Value.(formulaArg) + switch arg.Type { + case ArgString: + if arg.String != "" { + count++ + } + case ArgMatrix: + for _, row := range arg.Matrix { + for _, value := range row { + if value.String != "" { + count++ + } + } + } + } + } + result = fmt.Sprintf("%d", count) + return +} + // MEDIAN function returns the statistical median (the middle value) of a list // of supplied numbers. The syntax of the function is: // |