Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Excelize
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Globars Forks
Excelize
Commits
b6dd7648
Unverified
Commit
b6dd7648
authored
Jun 04, 2020
by
xuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fn: COUNTA
parent
b62950a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
+34
-3
calc.go
calc.go
+31
-3
calc_test.go
calc_test.go
+3
-0
No files found.
calc.go
View file @
b6dd7648
...
...
@@ -313,7 +313,7 @@ func calcAdd(opdStack *Stack) error {
return
nil
}
// calc
Add
evaluate subtraction arithmetic operations.
// calc
Subtract
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
}
// calc
Add
evaluate multiplication arithmetic operations.
// calc
Multiply
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
}
// calc
Add
evaluate division arithmetic operations.
// calc
Divide
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:
//
...
...
calc_test.go
View file @
b6dd7648
...
...
@@ -385,6 +385,9 @@ func TestCalcCellValue(t *testing.T) {
"=TRUNC(-99.999,2)"
:
"-99.99"
,
"=TRUNC(-99.999,-1)"
:
"-90"
,
// Statistical functions
// COUNTA
`=COUNTA()`
:
"0"
,
`=COUNTA(A1:A5,B2:B5,"text",1,2)`
:
"8"
,
// MEDIAN
"=MEDIAN(A1:A5,12)"
:
"2"
,
"=MEDIAN(A1:A5)"
:
"1.5"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment