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
fa2571a1
Unverified
Commit
fa2571a1
authored
May 30, 2020
by
xuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fn: SUMIF
parent
2ae63137
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
393 additions
and
160 deletions
+393
-160
calc.go
calc.go
+366
-154
calc_test.go
calc_test.go
+27
-6
No files found.
calc.go
View file @
fa2571a1
This diff is collapsed.
Click to expand it.
calc_test.go
View file @
fa2571a1
package
excelize
import
(
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func
TestCalcCellValue
(
t
*
testing
.
T
)
{
cellData
:=
[][]
interface
{}{
{
1
,
4
,
nil
,
"Month"
,
"Team"
,
"Sales"
},
{
2
,
5
,
nil
,
"Jan"
,
"North 1"
,
36693
},
{
3
,
nil
,
nil
,
"Jan"
,
"North 2"
,
22100
},
{
0
,
nil
,
nil
,
"Jan"
,
"South 1"
,
53321
},
{
nil
,
nil
,
nil
,
"Jan"
,
"South 2"
,
34440
},
{
nil
,
nil
,
nil
,
"Feb"
,
"North 1"
,
29889
},
{
nil
,
nil
,
nil
,
"Feb"
,
"North 2"
,
50090
},
{
nil
,
nil
,
nil
,
"Feb"
,
"South 1"
,
32080
},
{
nil
,
nil
,
nil
,
"Feb"
,
"South 2"
,
45500
},
}
prepareData
:=
func
()
*
File
{
f
:=
NewFile
()
f
.
SetCellValue
(
"Sheet1"
,
"A1"
,
1
)
f
.
SetCellValue
(
"Sheet1"
,
"A2"
,
2
)
f
.
SetCellValue
(
"Sheet1"
,
"A3"
,
3
)
f
.
SetCellValue
(
"Sheet1"
,
"A4"
,
0
)
f
.
SetCellValue
(
"Sheet1"
,
"B1"
,
4
)
f
.
SetCellValue
(
"Sheet1"
,
"B2"
,
5
)
f
or
r
,
row
:=
range
cellData
{
for
c
,
value
:=
range
row
{
cell
,
_
:=
CoordinatesToCellName
(
c
+
1
,
r
+
1
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
cell
,
value
)
)
}
}
return
f
}
...
...
@@ -348,6 +360,12 @@ func TestCalcCellValue(t *testing.T) {
"=((3+5*2)+3)/5+(-6)/4*2+3"
:
"3.2"
,
"=1+SUM(SUM(1,2*3),4)*-4/2+5+(4+2)*3"
:
"2"
,
"=1+SUM(SUM(1,2*3),4)*4/3+5+(4+2)*3"
:
"38.666666666666664"
,
// SUMIF
`=SUMIF(F1:F5, ">100")`
:
"146554"
,
`=SUMIF(D3:D7,"Jan",F2:F5)`
:
"112114"
,
`=SUMIF(D2:D9,"Feb",F2:F9)`
:
"157559"
,
`=SUMIF(E2:E9,"North 1",F2:F9)`
:
"66582"
,
`=SUMIF(E2:E9,"North*",F2:F9)`
:
"138772"
,
// SUMSQ
"=SUMSQ(A1:A4)"
:
"14"
,
"=SUMSQ(A1,B1,A2,B2,6)"
:
"82"
,
...
...
@@ -627,6 +645,8 @@ func TestCalcCellValue(t *testing.T) {
"=SUM(1*)"
:
"formula not valid"
,
"=SUM(1/)"
:
"formula not valid"
,
`=SUM("X")`
:
"#VALUE!"
,
// SUMIF
"=SUMIF()"
:
"SUMIF requires at least 2 argument"
,
// SUMSQ
`=SUMSQ("X")`
:
"#VALUE!"
,
// TAN
...
...
@@ -711,4 +731,5 @@ func TestCalcCellValue(t *testing.T) {
assert
.
NoError
(
t
,
f
.
SetCellFormula
(
"Sheet1"
,
"A1"
,
"=UNSUPPORT(A1)"
))
_
,
err
=
f
.
CalcCellValue
(
"Sheet1"
,
"A1"
)
assert
.
EqualError
(
t
,
err
,
"not support UNSUPPORT function"
)
assert
.
NoError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"TestCalcCellValue.xlsx"
)))
}
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