Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
1666d045
excelize
项目概览
此号慢热型
/
excelize
与 Fork 源项目一致
Fork自
xuri / excelize
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
已验证
提交
1666d045
编写于
12月 24, 2019
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimization: checking error in unit tests
上级
4e4a5b9b
变更
16
展开全部
隐藏空白更改
内联
并排
Showing
16 changed file
with
267 addition
and
246 deletion
+267
-246
.travis.yml
.travis.yml
+1
-0
cell_test.go
cell_test.go
+11
-7
cellmerged_test.go
cellmerged_test.go
+14
-8
chart_test.go
chart_test.go
+7
-14
col_test.go
col_test.go
+35
-18
datavalidation_test.go
datavalidation_test.go
+18
-28
excelize.go
excelize.go
+1
-1
excelize_test.go
excelize_test.go
+102
-84
file_test.go
file_test.go
+3
-1
picture_test.go
picture_test.go
+11
-24
pivotTable_test.go
pivotTable_test.go
+6
-6
rows_test.go
rows_test.go
+23
-24
sheet_test.go
sheet_test.go
+1
-1
sparkline_test.go
sparkline_test.go
+32
-28
stream.go
stream.go
+1
-1
table.go
table.go
+1
-1
未找到文件。
.travis.yml
浏览文件 @
1666d045
...
...
@@ -7,6 +7,7 @@ go:
-
1.10.x
-
1.11.x
-
1.12.x
-
1.13.x
os
:
-
linux
...
...
cell_test.go
浏览文件 @
1666d045
...
...
@@ -54,8 +54,8 @@ func TestSetCellFloat(t *testing.T) {
sheet
:=
"Sheet1"
t
.
Run
(
"with no decimal"
,
func
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
SetCellFloat
(
sheet
,
"A1"
,
123.0
,
-
1
,
64
)
f
.
SetCellFloat
(
sheet
,
"A2"
,
123.0
,
1
,
64
)
assert
.
NoError
(
t
,
f
.
SetCellFloat
(
sheet
,
"A1"
,
123.0
,
-
1
,
64
)
)
assert
.
NoError
(
t
,
f
.
SetCellFloat
(
sheet
,
"A2"
,
123.0
,
1
,
64
)
)
val
,
err
:=
f
.
GetCellValue
(
sheet
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"123"
,
val
,
"A1 should be 123"
)
...
...
@@ -66,7 +66,7 @@ func TestSetCellFloat(t *testing.T) {
t
.
Run
(
"with a decimal and precision limit"
,
func
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
SetCellFloat
(
sheet
,
"A1"
,
123.42
,
1
,
64
)
assert
.
NoError
(
t
,
f
.
SetCellFloat
(
sheet
,
"A1"
,
123.42
,
1
,
64
)
)
val
,
err
:=
f
.
GetCellValue
(
sheet
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"123.4"
,
val
,
"A1 should be 123.4"
)
...
...
@@ -74,7 +74,7 @@ func TestSetCellFloat(t *testing.T) {
t
.
Run
(
"with a decimal and no limit"
,
func
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
SetCellFloat
(
sheet
,
"A1"
,
123.42
,
-
1
,
64
)
assert
.
NoError
(
t
,
f
.
SetCellFloat
(
sheet
,
"A1"
,
123.42
,
-
1
,
64
)
)
val
,
err
:=
f
.
GetCellValue
(
sheet
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"123.42"
,
val
,
"A1 should be 123.42"
)
...
...
@@ -101,7 +101,7 @@ func TestGetCellFormula(t *testing.T) {
assert
.
EqualError
(
t
,
err
,
"sheet SheetN is not exist"
)
// Test get cell formula on no formula cell.
f
.
SetCellValue
(
"Sheet1"
,
"A1"
,
true
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"A1"
,
true
)
)
_
,
err
=
f
.
GetCellFormula
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
}
...
...
@@ -109,7 +109,9 @@ func TestGetCellFormula(t *testing.T) {
func
ExampleFile_SetCellFloat
()
{
f
:=
NewFile
()
var
x
=
3.14159265
f
.
SetCellFloat
(
"Sheet1"
,
"A1"
,
x
,
2
,
64
)
if
err
:=
f
.
SetCellFloat
(
"Sheet1"
,
"A1"
,
x
,
2
,
64
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
val
,
_
:=
f
.
GetCellValue
(
"Sheet1"
,
"A1"
)
fmt
.
Println
(
val
)
// Output: 3.14
...
...
@@ -122,7 +124,9 @@ func BenchmarkSetCellValue(b *testing.B) {
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
j
:=
0
;
j
<
len
(
values
);
j
++
{
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprint
(
cols
[
j
],
i
),
values
[
j
])
if
err
:=
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprint
(
cols
[
j
],
i
),
values
[
j
]);
err
!=
nil
{
b
.
Error
(
err
)
}
}
}
}
...
...
cellmerged_test.go
浏览文件 @
1666d045
...
...
@@ -21,14 +21,20 @@ func TestMergeCell(t *testing.T) {
assert
.
NoError
(
t
,
f
.
MergeCell
(
"Sheet1"
,
"H7"
,
"B15"
))
assert
.
NoError
(
t
,
f
.
MergeCell
(
"Sheet1"
,
"D11"
,
"F13"
))
assert
.
NoError
(
t
,
f
.
MergeCell
(
"Sheet1"
,
"G10"
,
"K12"
))
f
.
SetCellValue
(
"Sheet1"
,
"G11"
,
"set value in merged cell"
)
f
.
SetCellInt
(
"Sheet1"
,
"H11"
,
100
)
f
.
SetCellValue
(
"Sheet1"
,
"I11"
,
float64
(
0.5
))
f
.
SetCellHyperLink
(
"Sheet1"
,
"J11"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
f
.
SetCellFormula
(
"Sheet1"
,
"G12"
,
"SUM(Sheet1!B19,Sheet1!C19)"
)
f
.
GetCellValue
(
"Sheet1"
,
"H11"
)
f
.
GetCellValue
(
"Sheet2"
,
"A6"
)
// Merged cell ref is single coordinate.
f
.
GetCellFormula
(
"Sheet1"
,
"G12"
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"G11"
,
"set value in merged cell"
))
assert
.
NoError
(
t
,
f
.
SetCellInt
(
"Sheet1"
,
"H11"
,
100
))
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"I11"
,
float64
(
0.5
)))
assert
.
NoError
(
t
,
f
.
SetCellHyperLink
(
"Sheet1"
,
"J11"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
))
assert
.
NoError
(
t
,
f
.
SetCellFormula
(
"Sheet1"
,
"G12"
,
"SUM(Sheet1!B19,Sheet1!C19)"
))
value
,
err
:=
f
.
GetCellValue
(
"Sheet1"
,
"H11"
)
assert
.
Equal
(
t
,
"0.5"
,
value
)
assert
.
NoError
(
t
,
err
)
value
,
err
=
f
.
GetCellValue
(
"Sheet2"
,
"A6"
)
// Merged cell ref is single coordinate.
assert
.
Equal
(
t
,
""
,
value
)
assert
.
NoError
(
t
,
err
)
value
,
err
=
f
.
GetCellFormula
(
"Sheet1"
,
"G12"
)
assert
.
Equal
(
t
,
"SUM(Sheet1!B19,Sheet1!C19)"
,
value
)
assert
.
NoError
(
t
,
err
)
f
.
NewSheet
(
"Sheet3"
)
assert
.
NoError
(
t
,
f
.
MergeCell
(
"Sheet3"
,
"D11"
,
"F13"
))
...
...
chart_test.go
浏览文件 @
1666d045
...
...
@@ -22,7 +22,7 @@ func TestChartSize(t *testing.T) {
"D1"
:
"Pear"
,
}
for
cell
,
v
:=
range
categories
{
xlsx
.
SetCellValue
(
sheet1
,
cell
,
v
)
assert
.
NoError
(
t
,
xlsx
.
SetCellValue
(
sheet1
,
cell
,
v
)
)
}
values
:=
map
[
string
]
int
{
...
...
@@ -37,29 +37,22 @@ func TestChartSize(t *testing.T) {
"D4"
:
8
,
}
for
cell
,
v
:=
range
values
{
xlsx
.
SetCellValue
(
sheet1
,
cell
,
v
)
assert
.
NoError
(
t
,
xlsx
.
SetCellValue
(
sheet1
,
cell
,
v
)
)
}
xlsx
.
AddChart
(
"Sheet1"
,
"E4"
,
`{"type":"col3DClustered","dimension":{"width":640, "height":480},`
+
assert
.
NoError
(
t
,
xlsx
.
AddChart
(
"Sheet1"
,
"E4"
,
`{"type":"col3DClustered","dimension":{"width":640, "height":480},`
+
`"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},`
+
`{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},`
+
`{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],`
+
`"title":{"name":"3D Clustered Column Chart"}}`
)
`"title":{"name":"3D Clustered Column Chart"}}`
)
)
var
(
buffer
bytes
.
Buffer
)
var
buffer
bytes
.
Buffer
// Save xlsx file by the given path.
err
:=
xlsx
.
Write
(
&
buffer
)
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
xlsx
.
Write
(
&
buffer
))
newFile
,
err
:=
OpenReader
(
&
buffer
)
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
err
)
chartsNum
:=
newFile
.
countCharts
()
if
!
assert
.
Equal
(
t
,
1
,
chartsNum
,
"Expected 1 chart, actual %d"
,
chartsNum
)
{
...
...
col_test.go
浏览文件 @
1666d045
...
...
@@ -37,17 +37,29 @@ func TestColumnVisibility(t *testing.T) {
t
.
Run
(
"TestBook3"
,
func
(
t
*
testing
.
T
)
{
f
,
err
:=
prepareTestBook3
()
assert
.
NoError
(
t
,
err
)
f
.
GetColVisible
(
"Sheet1"
,
"B"
)
visible
,
err
:=
f
.
GetColVisible
(
"Sheet1"
,
"B"
)
assert
.
Equal
(
t
,
true
,
visible
)
assert
.
NoError
(
t
,
err
)
})
}
func
TestOutlineLevel
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
GetColOutlineLevel
(
"Sheet1"
,
"D"
)
level
,
err
:=
f
.
GetColOutlineLevel
(
"Sheet1"
,
"D"
)
assert
.
Equal
(
t
,
uint8
(
0
),
level
)
assert
.
NoError
(
t
,
err
)
f
.
NewSheet
(
"Sheet2"
)
assert
.
NoError
(
t
,
f
.
SetColOutlineLevel
(
"Sheet1"
,
"D"
,
4
))
f
.
GetColOutlineLevel
(
"Sheet1"
,
"D"
)
f
.
GetColOutlineLevel
(
"Shee2"
,
"A"
)
level
,
err
=
f
.
GetColOutlineLevel
(
"Sheet1"
,
"D"
)
assert
.
Equal
(
t
,
uint8
(
4
),
level
)
assert
.
NoError
(
t
,
err
)
level
,
err
=
f
.
GetColOutlineLevel
(
"Shee2"
,
"A"
)
assert
.
Equal
(
t
,
uint8
(
0
),
level
)
assert
.
EqualError
(
t
,
err
,
"sheet Shee2 is not exist"
)
assert
.
NoError
(
t
,
f
.
SetColWidth
(
"Sheet2"
,
"A"
,
"D"
,
13
))
assert
.
NoError
(
t
,
f
.
SetColOutlineLevel
(
"Sheet2"
,
"B"
,
2
))
assert
.
NoError
(
t
,
f
.
SetRowOutlineLevel
(
"Sheet1"
,
2
,
7
))
...
...
@@ -56,7 +68,7 @@ func TestOutlineLevel(t *testing.T) {
// Test set row outline level on not exists worksheet.
assert
.
EqualError
(
t
,
f
.
SetRowOutlineLevel
(
"SheetN"
,
1
,
4
),
"sheet SheetN is not exist"
)
// Test get row outline level on not exists worksheet.
_
,
err
:
=
f
.
GetRowOutlineLevel
(
"SheetN"
,
1
)
_
,
err
=
f
.
GetRowOutlineLevel
(
"SheetN"
,
1
)
assert
.
EqualError
(
t
,
err
,
"sheet SheetN is not exist"
)
// Test set and get column outline level with illegal cell coordinates.
...
...
@@ -68,7 +80,7 @@ func TestOutlineLevel(t *testing.T) {
assert
.
EqualError
(
t
,
f
.
SetColOutlineLevel
(
"SheetN"
,
"E"
,
2
),
"sheet SheetN is not exist"
)
assert
.
EqualError
(
t
,
f
.
SetRowOutlineLevel
(
"Sheet1"
,
0
,
1
),
"invalid row number 0"
)
level
,
err
:
=
f
.
GetRowOutlineLevel
(
"Sheet1"
,
2
)
level
,
err
=
f
.
GetRowOutlineLevel
(
"Sheet1"
,
2
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
uint8
(
7
),
level
)
...
...
@@ -83,7 +95,7 @@ func TestOutlineLevel(t *testing.T) {
f
,
err
=
OpenFile
(
filepath
.
Join
(
"test"
,
"Book1.xlsx"
))
assert
.
NoError
(
t
,
err
)
f
.
SetColOutlineLevel
(
"Sheet2"
,
"B"
,
2
)
assert
.
NoError
(
t
,
f
.
SetColOutlineLevel
(
"Sheet2"
,
"B"
,
2
)
)
}
func
TestSetColStyle
(
t
*
testing
.
T
)
{
...
...
@@ -105,13 +117,18 @@ func TestSetColStyle(t *testing.T) {
func
TestColWidth
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
SetColWidth
(
"Sheet1"
,
"B"
,
"A"
,
12
)
f
.
SetColWidth
(
"Sheet1"
,
"A"
,
"B"
,
12
)
f
.
GetColWidth
(
"Sheet1"
,
"A"
)
f
.
GetColWidth
(
"Sheet1"
,
"C"
)
assert
.
NoError
(
t
,
f
.
SetColWidth
(
"Sheet1"
,
"B"
,
"A"
,
12
))
assert
.
NoError
(
t
,
f
.
SetColWidth
(
"Sheet1"
,
"A"
,
"B"
,
12
))
width
,
err
:=
f
.
GetColWidth
(
"Sheet1"
,
"A"
)
assert
.
Equal
(
t
,
float64
(
12
),
width
)
assert
.
NoError
(
t
,
err
)
width
,
err
=
f
.
GetColWidth
(
"Sheet1"
,
"C"
)
assert
.
Equal
(
t
,
float64
(
64
),
width
)
assert
.
NoError
(
t
,
err
)
// Test set and get column width with illegal cell coordinates.
_
,
err
:=
f
.
GetColWidth
(
"Sheet1"
,
"*"
)
width
,
err
=
f
.
GetColWidth
(
"Sheet1"
,
"*"
)
assert
.
Equal
(
t
,
float64
(
64
),
width
)
assert
.
EqualError
(
t
,
err
,
`invalid column name "*"`
)
assert
.
EqualError
(
t
,
f
.
SetColWidth
(
"Sheet1"
,
"*"
,
"B"
,
1
),
`invalid column name "*"`
)
assert
.
EqualError
(
t
,
f
.
SetColWidth
(
"Sheet1"
,
"A"
,
"*"
,
1
),
`invalid column name "*"`
)
...
...
@@ -133,8 +150,8 @@ func TestInsertCol(t *testing.T) {
fillCells
(
f
,
sheet1
,
10
,
10
)
f
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
f
.
MergeCell
(
sheet1
,
"A1"
,
"C3"
)
assert
.
NoError
(
t
,
f
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
)
assert
.
NoError
(
t
,
f
.
MergeCell
(
sheet1
,
"A1"
,
"C3"
)
)
assert
.
NoError
(
t
,
f
.
AutoFilter
(
sheet1
,
"A2"
,
"B2"
,
`{"column":"B","expression":"x != blanks"}`
))
assert
.
NoError
(
t
,
f
.
InsertCol
(
sheet1
,
"A"
))
...
...
@@ -151,11 +168,11 @@ func TestRemoveCol(t *testing.T) {
fillCells
(
f
,
sheet1
,
10
,
15
)
f
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
f
.
SetCellHyperLink
(
sheet1
,
"C5"
,
"https://github.com"
,
"External"
)
assert
.
NoError
(
t
,
f
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
)
assert
.
NoError
(
t
,
f
.
SetCellHyperLink
(
sheet1
,
"C5"
,
"https://github.com"
,
"External"
)
)
f
.
MergeCell
(
sheet1
,
"A1"
,
"B1"
)
f
.
MergeCell
(
sheet1
,
"A2"
,
"B2"
)
assert
.
NoError
(
t
,
f
.
MergeCell
(
sheet1
,
"A1"
,
"B1"
)
)
assert
.
NoError
(
t
,
f
.
MergeCell
(
sheet1
,
"A2"
,
"B2"
)
)
assert
.
NoError
(
t
,
f
.
RemoveCol
(
sheet1
,
"A"
))
assert
.
NoError
(
t
,
f
.
RemoveCol
(
sheet1
,
"A"
))
...
...
datavalidation_test.go
浏览文件 @
1666d045
...
...
@@ -24,53 +24,45 @@ func TestDataValidation(t *testing.T) {
dvRange
:=
NewDataValidation
(
true
)
dvRange
.
Sqref
=
"A1:B2"
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorBetween
)
assert
.
NoError
(
t
,
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorBetween
)
)
dvRange
.
SetError
(
DataValidationErrorStyleStop
,
"error title"
,
"error body"
)
dvRange
.
SetError
(
DataValidationErrorStyleWarning
,
"error title"
,
"error body"
)
dvRange
.
SetError
(
DataValidationErrorStyleInformation
,
"error title"
,
"error body"
)
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
if
!
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
))
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
dvRange
=
NewDataValidation
(
true
)
dvRange
.
Sqref
=
"A3:B4"
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorGreaterThan
)
assert
.
NoError
(
t
,
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorGreaterThan
)
)
dvRange
.
SetInput
(
"input title"
,
"input body"
)
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
if
!
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
))
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
dvRange
=
NewDataValidation
(
true
)
dvRange
.
Sqref
=
"A5:B6"
dvRange
.
SetDropList
([]
string
{
"1"
,
"2"
,
"3"
})
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
if
!
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
dvRange
.
SetDropList
([]
string
{
"1"
,
"2"
,
"3"
}))
assert
.
NoError
(
t
,
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
))
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
}
func
TestDataValidationError
(
t
*
testing
.
T
)
{
resultFile
:=
filepath
.
Join
(
"test"
,
"TestDataValidationError.xlsx"
)
f
:=
NewFile
()
f
.
SetCellStr
(
"Sheet1"
,
"E1"
,
"E1"
)
f
.
SetCellStr
(
"Sheet1"
,
"E2"
,
"E2"
)
f
.
SetCellStr
(
"Sheet1"
,
"E3"
,
"E3"
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
"Sheet1"
,
"E1"
,
"E1"
)
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
"Sheet1"
,
"E2"
,
"E2"
)
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
"Sheet1"
,
"E3"
,
"E3"
)
)
dvRange
:=
NewDataValidation
(
true
)
dvRange
.
SetSqref
(
"A7:B8"
)
dvRange
.
SetSqref
(
"A7:B8"
)
dvRange
.
SetSqrefDropList
(
"$E$1:$E$3"
,
true
)
assert
.
NoError
(
t
,
dvRange
.
SetSqrefDropList
(
"$E$1:$E$3"
,
true
)
)
err
:=
dvRange
.
SetSqrefDropList
(
"$E$1:$E$3"
,
false
)
assert
.
EqualError
(
t
,
err
,
"cross-sheet sqref cell are not supported"
)
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
if
!
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
))
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
dvRange
=
NewDataValidation
(
true
)
err
=
dvRange
.
SetDropList
(
make
([]
string
,
258
))
...
...
@@ -79,13 +71,11 @@ func TestDataValidationError(t *testing.T) {
return
}
assert
.
EqualError
(
t
,
err
,
"data validation must be 0-255 characters"
)
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorGreaterThan
)
assert
.
NoError
(
t
,
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorGreaterThan
)
)
dvRange
.
SetSqref
(
"A9:B10"
)
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
if
!
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
AddDataValidation
(
"Sheet1"
,
dvRange
))
assert
.
NoError
(
t
,
f
.
SaveAs
(
resultFile
))
// Test width invalid data validation formula.
dvRange
.
Formula1
=
strings
.
Repeat
(
"s"
,
dataValidationFormulaStrLen
+
22
)
...
...
excelize.go
浏览文件 @
1666d045
...
...
@@ -138,7 +138,7 @@ func (f *File) setDefaultTimeStyle(sheet, axis string, format int) error {
}
if
s
==
0
{
style
,
_
:=
f
.
NewStyle
(
`{"number_format": `
+
strconv
.
Itoa
(
format
)
+
`}`
)
f
.
SetCellStyle
(
sheet
,
axis
,
axis
,
style
)
_
=
f
.
SetCellStyle
(
sheet
,
axis
,
axis
,
style
)
}
return
err
}
...
...
excelize_test.go
浏览文件 @
1666d045
此差异已折叠。
点击以展开。
file_test.go
浏览文件 @
1666d045
...
...
@@ -14,7 +14,9 @@ func BenchmarkWrite(b *testing.B) {
if
err
!=
nil
{
panic
(
err
)
}
f
.
SetCellDefault
(
"Sheet1"
,
val
,
s
)
if
err
:=
f
.
SetCellDefault
(
"Sheet1"
,
val
,
s
);
err
!=
nil
{
panic
(
err
)
}
}
}
// Save xlsx file by the given path.
...
...
picture_test.go
浏览文件 @
1666d045
...
...
@@ -25,7 +25,9 @@ func BenchmarkAddPictureFromBytes(b *testing.B) {
}
b
.
ResetTimer
()
for
i
:=
1
;
i
<=
b
.
N
;
i
++
{
f
.
AddPictureFromBytes
(
"Sheet1"
,
fmt
.
Sprint
(
"A"
,
i
),
""
,
"excel"
,
".png"
,
imgFile
)
if
err
:=
f
.
AddPictureFromBytes
(
"Sheet1"
,
fmt
.
Sprint
(
"A"
,
i
),
""
,
"excel"
,
".png"
,
imgFile
);
err
!=
nil
{
b
.
Error
(
err
)
}
}
}
...
...
@@ -36,23 +38,14 @@ func TestAddPicture(t *testing.T) {
}
// Test add picture to worksheet with offset and location hyperlink.
err
=
f
.
AddPicture
(
"Sheet2"
,
"I9"
,
filepath
.
Join
(
"test"
,
"images"
,
"excel.jpg"
),
`{"x_offset": 140, "y_offset": 120, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`
)
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
AddPicture
(
"Sheet2"
,
"I9"
,
filepath
.
Join
(
"test"
,
"images"
,
"excel.jpg"
),
`{"x_offset": 140, "y_offset": 120, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`
))
// Test add picture to worksheet with offset, external hyperlink and positioning.
err
=
f
.
AddPicture
(
"Sheet1"
,
"F21"
,
filepath
.
Join
(
"test"
,
"images"
,
"excel.jpg"
),
`{"x_offset": 10, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "positioning": "oneCell"}`
)
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
AddPicture
(
"Sheet1"
,
"F21"
,
filepath
.
Join
(
"test"
,
"images"
,
"excel.jpg"
),
`{"x_offset": 10, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "positioning": "oneCell"}`
))
file
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
"test"
,
"images"
,
"excel.png"
))
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
err
)
// Test add picture to worksheet from bytes.
assert
.
NoError
(
t
,
f
.
AddPictureFromBytes
(
"Sheet1"
,
"Q1"
,
""
,
"Excel Logo"
,
".png"
,
file
))
...
...
@@ -69,9 +62,7 @@ func TestAddPicture(t *testing.T) {
func
TestAddPictureErrors
(
t
*
testing
.
T
)
{
xlsx
,
err
:=
OpenFile
(
filepath
.
Join
(
"test"
,
"Book1.xlsx"
))
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
err
)
// Test add picture to worksheet with invalid file path.
err
=
xlsx
.
AddPicture
(
"Sheet1"
,
"G21"
,
filepath
.
Join
(
"test"
,
"not_exists_dir"
,
"not_exists.icon"
),
""
)
...
...
@@ -127,14 +118,10 @@ func TestGetPicture(t *testing.T) {
f
.
deleteSheetRelationships
(
""
,
""
)
// Try to get picture from a local storage file.
if
!
assert
.
NoError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"TestGetPicture.xlsx"
)))
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"TestGetPicture.xlsx"
)))
f
,
err
=
OpenFile
(
filepath
.
Join
(
"test"
,
"TestGetPicture.xlsx"
))
if
!
assert
.
NoError
(
t
,
err
)
{
t
.
FailNow
()
}
assert
.
NoError
(
t
,
err
)
file
,
raw
,
err
=
f
.
GetPicture
(
"Sheet1"
,
"F21"
)
assert
.
NoError
(
t
,
err
)
...
...
pivotTable_test.go
浏览文件 @
1666d045
...
...
@@ -16,13 +16,13 @@ func TestAddPivotTable(t *testing.T) {
year
:=
[]
int
{
2017
,
2018
,
2019
}
types
:=
[]
string
{
"Meat"
,
"Dairy"
,
"Beverages"
,
"Produce"
}
region
:=
[]
string
{
"East"
,
"West"
,
"North"
,
"South"
}
f
.
SetSheetRow
(
"Sheet1"
,
"A1"
,
&
[]
string
{
"Month"
,
"Year"
,
"Type"
,
"Sales"
,
"Region"
}
)
assert
.
NoError
(
t
,
f
.
SetSheetRow
(
"Sheet1"
,
"A1"
,
&
[]
string
{
"Month"
,
"Year"
,
"Type"
,
"Sales"
,
"Region"
})
)
for
i
:=
0
;
i
<
30
;
i
++
{
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"A%d"
,
i
+
2
),
month
[
rand
.
Intn
(
12
)]
)
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"B%d"
,
i
+
2
),
year
[
rand
.
Intn
(
3
)]
)
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"C%d"
,
i
+
2
),
types
[
rand
.
Intn
(
4
)]
)
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"D%d"
,
i
+
2
),
rand
.
Intn
(
5000
))
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"E%d"
,
i
+
2
),
region
[
rand
.
Intn
(
4
)]
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"A%d"
,
i
+
2
),
month
[
rand
.
Intn
(
12
)])
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"B%d"
,
i
+
2
),
year
[
rand
.
Intn
(
3
)])
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"C%d"
,
i
+
2
),
types
[
rand
.
Intn
(
4
)])
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"D%d"
,
i
+
2
),
rand
.
Intn
(
5000
)
))
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
fmt
.
Sprintf
(
"E%d"
,
i
+
2
),
region
[
rand
.
Intn
(
4
)])
)
}
assert
.
NoError
(
t
,
f
.
AddPivotTable
(
&
PivotTableOption
{
DataRange
:
"Sheet1!$A$1:$E$31"
,
...
...
rows_test.go
浏览文件 @
1666d045
...
...
@@ -69,7 +69,7 @@ func TestRowsIterator(t *testing.T) {
f
=
NewFile
()
cells
:=
[]
string
{
"C1"
,
"E1"
,
"A3"
,
"B3"
,
"C3"
,
"D3"
,
"E3"
}
for
_
,
cell
:=
range
cells
{
f
.
SetCellValue
(
"Sheet1"
,
cell
,
1
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
cell
,
1
)
)
}
rows
,
err
=
f
.
Rows
(
"Sheet1"
)
require
.
NoError
(
t
,
err
)
...
...
@@ -169,8 +169,12 @@ func TestRowVisibility(t *testing.T) {
f
.
NewSheet
(
"Sheet3"
)
assert
.
NoError
(
t
,
f
.
SetRowVisible
(
"Sheet3"
,
2
,
false
))
assert
.
NoError
(
t
,
f
.
SetRowVisible
(
"Sheet3"
,
2
,
true
))
f
.
GetRowVisible
(
"Sheet3"
,
2
)
f
.
GetRowVisible
(
"Sheet3"
,
25
)
visiable
,
err
:=
f
.
GetRowVisible
(
"Sheet3"
,
2
)
assert
.
Equal
(
t
,
true
,
visiable
)
assert
.
NoError
(
t
,
err
)
visiable
,
err
=
f
.
GetRowVisible
(
"Sheet3"
,
25
)
assert
.
Equal
(
t
,
false
,
visiable
)
assert
.
NoError
(
t
,
err
)
assert
.
EqualError
(
t
,
f
.
SetRowVisible
(
"Sheet3"
,
0
,
true
),
"invalid row number 0"
)
assert
.
EqualError
(
t
,
f
.
SetRowVisible
(
"SheetN"
,
2
,
false
),
"sheet SheetN is not exist"
)
...
...
@@ -194,7 +198,7 @@ func TestRemoveRow(t *testing.T) {
)
fillCells
(
f
,
sheet1
,
colCount
,
rowCount
)
f
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
assert
.
NoError
(
t
,
f
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
)
assert
.
EqualError
(
t
,
f
.
RemoveRow
(
sheet1
,
-
1
),
"invalid row number -1"
)
...
...
@@ -205,7 +209,7 @@ func TestRemoveRow(t *testing.T) {
t
.
FailNow
()
}
f
.
MergeCell
(
sheet1
,
"B3"
,
"B5"
)
assert
.
NoError
(
t
,
f
.
MergeCell
(
sheet1
,
"B3"
,
"B5"
)
)
assert
.
NoError
(
t
,
f
.
RemoveRow
(
sheet1
,
2
))
if
!
assert
.
Len
(
t
,
r
.
SheetData
.
Row
,
rowCount
-
2
)
{
...
...
@@ -255,7 +259,7 @@ func TestInsertRow(t *testing.T) {
)
fillCells
(
xlsx
,
sheet1
,
colCount
,
rowCount
)
xlsx
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
assert
.
NoError
(
t
,
xlsx
.
SetCellHyperLink
(
sheet1
,
"A5"
,
"https://github.com/360EntSecGroup-Skylar/excelize"
,
"External"
)
)
assert
.
EqualError
(
t
,
xlsx
.
InsertRow
(
sheet1
,
-
1
),
"invalid row number -1"
)
...
...
@@ -305,8 +309,8 @@ func TestDuplicateRowFromSingleRow(t *testing.T) {
t
.
Run
(
"FromSingleRow"
,
func
(
t
*
testing
.
T
)
{
xlsx
:=
NewFile
()
xlsx
.
SetCellStr
(
sheet
,
"A1"
,
cells
[
"A1"
]
)
xlsx
.
SetCellStr
(
sheet
,
"B1"
,
cells
[
"B1"
]
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
"A1"
,
cells
[
"A1"
])
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
"B1"
,
cells
[
"B1"
])
)
assert
.
NoError
(
t
,
xlsx
.
DuplicateRow
(
sheet
,
1
))
if
!
assert
.
NoError
(
t
,
xlsx
.
SaveAs
(
fmt
.
Sprintf
(
outFile
,
"TestDuplicateRow.FromSingleRow_1"
)))
{
...
...
@@ -358,13 +362,13 @@ func TestDuplicateRowUpdateDuplicatedRows(t *testing.T) {
t
.
Run
(
"UpdateDuplicatedRows"
,
func
(
t
*
testing
.
T
)
{
xlsx
:=
NewFile
()
xlsx
.
SetCellStr
(
sheet
,
"A1"
,
cells
[
"A1"
]
)
xlsx
.
SetCellStr
(
sheet
,
"B1"
,
cells
[
"B1"
]
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
"A1"
,
cells
[
"A1"
])
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
"B1"
,
cells
[
"B1"
])
)
assert
.
NoError
(
t
,
xlsx
.
DuplicateRow
(
sheet
,
1
))
xlsx
.
SetCellStr
(
sheet
,
"A2"
,
cells
[
"A2"
]
)
xlsx
.
SetCellStr
(
sheet
,
"B2"
,
cells
[
"B2"
]
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
"A2"
,
cells
[
"A2"
])
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
"B2"
,
cells
[
"B2"
])
)
if
!
assert
.
NoError
(
t
,
xlsx
.
SaveAs
(
fmt
.
Sprintf
(
outFile
,
"TestDuplicateRow.UpdateDuplicatedRows"
)))
{
t
.
FailNow
()
...
...
@@ -399,8 +403,7 @@ func TestDuplicateRowFirstOfMultipleRows(t *testing.T) {
newFileWithDefaults
:=
func
()
*
File
{
f
:=
NewFile
()
for
cell
,
val
:=
range
cells
{
f
.
SetCellStr
(
sheet
,
cell
,
val
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
sheet
,
cell
,
val
))
}
return
f
}
...
...
@@ -514,8 +517,7 @@ func TestDuplicateRowWithLargeOffsetToMiddleOfData(t *testing.T) {
newFileWithDefaults
:=
func
()
*
File
{
f
:=
NewFile
()
for
cell
,
val
:=
range
cells
{
f
.
SetCellStr
(
sheet
,
cell
,
val
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
sheet
,
cell
,
val
))
}
return
f
}
...
...
@@ -560,8 +562,7 @@ func TestDuplicateRowWithLargeOffsetToEmptyRows(t *testing.T) {
newFileWithDefaults
:=
func
()
*
File
{
f
:=
NewFile
()
for
cell
,
val
:=
range
cells
{
f
.
SetCellStr
(
sheet
,
cell
,
val
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
sheet
,
cell
,
val
))
}
return
f
}
...
...
@@ -606,8 +607,7 @@ func TestDuplicateRowInsertBefore(t *testing.T) {
newFileWithDefaults
:=
func
()
*
File
{
f
:=
NewFile
()
for
cell
,
val
:=
range
cells
{
f
.
SetCellStr
(
sheet
,
cell
,
val
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
sheet
,
cell
,
val
))
}
return
f
}
...
...
@@ -653,8 +653,7 @@ func TestDuplicateRowInsertBeforeWithLargeOffset(t *testing.T) {
newFileWithDefaults
:=
func
()
*
File
{
f
:=
NewFile
()
for
cell
,
val
:=
range
cells
{
f
.
SetCellStr
(
sheet
,
cell
,
val
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
sheet
,
cell
,
val
))
}
return
f
}
...
...
@@ -704,7 +703,7 @@ func TestDuplicateRowInvalidRownum(t *testing.T) {
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
xlsx
:=
NewFile
()
for
col
,
val
:=
range
cells
{
xlsx
.
SetCellStr
(
sheet
,
col
,
val
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
col
,
val
)
)
}
assert
.
EqualError
(
t
,
xlsx
.
DuplicateRow
(
sheet
,
row
),
fmt
.
Sprintf
(
"invalid row number %d"
,
row
))
...
...
@@ -726,7 +725,7 @@ func TestDuplicateRowInvalidRownum(t *testing.T) {
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
xlsx
:=
NewFile
()
for
col
,
val
:=
range
cells
{
xlsx
.
SetCellStr
(
sheet
,
col
,
val
)
assert
.
NoError
(
t
,
xlsx
.
SetCellStr
(
sheet
,
col
,
val
)
)
}
assert
.
EqualError
(
t
,
xlsx
.
DuplicateRowTo
(
sheet
,
row1
,
row2
),
fmt
.
Sprintf
(
"invalid row number %d"
,
row1
))
...
...
sheet_test.go
浏览文件 @
1666d045
...
...
@@ -192,7 +192,7 @@ func TestGetPageLayout(t *testing.T) {
func
TestSetHeaderFooter
(
t
*
testing
.
T
)
{
f
:=
excelize
.
NewFile
()
f
.
SetCellStr
(
"Sheet1"
,
"A1"
,
"Test SetHeaderFooter"
)
assert
.
NoError
(
t
,
f
.
SetCellStr
(
"Sheet1"
,
"A1"
,
"Test SetHeaderFooter"
)
)
// Test set header and footer on not exists worksheet.
assert
.
EqualError
(
t
,
f
.
SetHeaderFooter
(
"SheetN"
,
nil
),
"sheet SheetN is not exist"
)
// Test set header and footer with illegal setting.
...
...
sparkline_test.go
浏览文件 @
1666d045
...
...
@@ -17,40 +17,40 @@ func TestAddSparkline(t *testing.T) {
assert
.
NoError
(
t
,
f
.
SetCellStyle
(
"Sheet1"
,
"A1"
,
"B1"
,
style
))
assert
.
NoError
(
t
,
f
.
SetSheetViewOptions
(
"Sheet1"
,
0
,
ZoomScale
(
150
)))
f
.
SetColWidth
(
"Sheet1"
,
"A"
,
"A"
,
14
)
f
.
SetColWidth
(
"Sheet1"
,
"B"
,
"B"
,
50
)
assert
.
NoError
(
t
,
f
.
SetColWidth
(
"Sheet1"
,
"A"
,
"A"
,
14
)
)
assert
.
NoError
(
t
,
f
.
SetColWidth
(
"Sheet1"
,
"B"
,
"B"
,
50
)
)
// Headings
f
.
SetCellValue
(
"Sheet1"
,
"A1"
,
"Sparkline"
)
f
.
SetCellValue
(
"Sheet1"
,
"B1"
,
"Description"
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"A1"
,
"Sparkline"
)
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B1"
,
"Description"
)
)
f
.
SetCellValue
(
"Sheet1"
,
"B2"
,
`A default "line" sparkline.`
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B2"
,
`A default "line" sparkline.`
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A2"
},
Range
:
[]
string
{
"Sheet3!A1:J1"
},
}))
f
.
SetCellValue
(
"Sheet1"
,
"B3"
,
`A default "column" sparkline.`
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B3"
,
`A default "column" sparkline.`
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A3"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
Type
:
"column"
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B4"
,
`A default "win/loss" sparkline.`
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B4"
,
`A default "win/loss" sparkline.`
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A4"
},
Range
:
[]
string
{
"Sheet3!A3:J3"
},
Type
:
"win_loss"
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B6"
,
"Line with markers."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B6"
,
"Line with markers."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A6"
},
Range
:
[]
string
{
"Sheet3!A1:J1"
},
Markers
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B7"
,
"Line with high and low points."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B7"
,
"Line with high and low points."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A7"
},
Range
:
[]
string
{
"Sheet3!A1:J1"
},
...
...
@@ -58,7 +58,7 @@ func TestAddSparkline(t *testing.T) {
Low
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B8"
,
"Line with first and last point markers."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B8"
,
"Line with first and last point markers."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A8"
},
Range
:
[]
string
{
"Sheet3!A1:J1"
},
...
...
@@ -66,28 +66,28 @@ func TestAddSparkline(t *testing.T) {
Last
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B9"
,
"Line with negative point markers."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B9"
,
"Line with negative point markers."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A9"
},
Range
:
[]
string
{
"Sheet3!A1:J1"
},
Negative
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B10"
,
"Line with axis."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B10"
,
"Line with axis."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A10"
},
Range
:
[]
string
{
"Sheet3!A1:J1"
},
Axis
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B12"
,
"Column with default style (1)."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B12"
,
"Column with default style (1)."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A12"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
Type
:
"column"
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B13"
,
"Column with style 2."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B13"
,
"Column with style 2."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A13"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
...
...
@@ -95,7 +95,7 @@ func TestAddSparkline(t *testing.T) {
Style
:
2
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B14"
,
"Column with style 3."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B14"
,
"Column with style 3."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A14"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
...
...
@@ -103,7 +103,7 @@ func TestAddSparkline(t *testing.T) {
Style
:
3
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B15"
,
"Column with style 4."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B15"
,
"Column with style 4."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A15"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
...
...
@@ -111,7 +111,7 @@ func TestAddSparkline(t *testing.T) {
Style
:
4
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B16"
,
"Column with style 5."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B16"
,
"Column with style 5."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A16"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
...
...
@@ -119,7 +119,7 @@ func TestAddSparkline(t *testing.T) {
Style
:
5
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B17"
,
"Column with style 6."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B17"
,
"Column with style 6."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A17"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
...
...
@@ -127,7 +127,7 @@ func TestAddSparkline(t *testing.T) {
Style
:
6
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B18"
,
"Column with a user defined color."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B18"
,
"Column with a user defined color."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A18"
},
Range
:
[]
string
{
"Sheet3!A2:J2"
},
...
...
@@ -135,14 +135,14 @@ func TestAddSparkline(t *testing.T) {
SeriesColor
:
"#E965E0"
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B20"
,
"A win/loss sparkline."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B20"
,
"A win/loss sparkline."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A20"
},
Range
:
[]
string
{
"Sheet3!A3:J3"
},
Type
:
"win_loss"
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B21"
,
"A win/loss sparkline with negative points highlighted."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B21"
,
"A win/loss sparkline with negative points highlighted."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A21"
},
Range
:
[]
string
{
"Sheet3!A3:J3"
},
...
...
@@ -150,7 +150,7 @@ func TestAddSparkline(t *testing.T) {
Negative
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B23"
,
"A left to right column (the default)."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B23"
,
"A left to right column (the default)."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A23"
},
Range
:
[]
string
{
"Sheet3!A4:J4"
},
...
...
@@ -158,7 +158,7 @@ func TestAddSparkline(t *testing.T) {
Style
:
20
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B24"
,
"A right to left column."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B24"
,
"A right to left column."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A24"
},
Range
:
[]
string
{
"Sheet3!A4:J4"
},
...
...
@@ -167,16 +167,16 @@ func TestAddSparkline(t *testing.T) {
Reverse
:
true
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"B25"
,
"Sparkline and text in one cell."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B25"
,
"Sparkline and text in one cell."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A25"
},
Range
:
[]
string
{
"Sheet3!A4:J4"
},
Type
:
"column"
,
Style
:
20
,
}))
f
.
SetCellValue
(
"Sheet1"
,
"A25"
,
"Growth"
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"A25"
,
"Growth"
)
)
f
.
SetCellValue
(
"Sheet1"
,
"B27"
,
"A grouped sparkline. Changes are applied to all three."
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"B27"
,
"A grouped sparkline. Changes are applied to all three."
)
)
assert
.
NoError
(
t
,
f
.
AddSparkline
(
"Sheet1"
,
&
SparklineOption
{
Location
:
[]
string
{
"A27"
,
"A28"
,
"A29"
},
Range
:
[]
string
{
"Sheet3!A5:J5"
,
"Sheet3!A6:J6"
,
"Sheet3!A7:J7"
},
...
...
@@ -297,10 +297,14 @@ func prepareSparklineDataset() *File {
f
.
NewSheet
(
"Sheet2"
)
f
.
NewSheet
(
"Sheet3"
)
for
row
,
data
:=
range
sheet2
{
f
.
SetSheetRow
(
"Sheet2"
,
fmt
.
Sprintf
(
"A%d"
,
row
+
1
),
&
data
)
if
err
:=
f
.
SetSheetRow
(
"Sheet2"
,
fmt
.
Sprintf
(
"A%d"
,
row
+
1
),
&
data
);
err
!=
nil
{
panic
(
err
)
}
}
for
row
,
data
:=
range
sheet3
{
f
.
SetSheetRow
(
"Sheet3"
,
fmt
.
Sprintf
(
"A%d"
,
row
+
1
),
&
data
)
if
err
:=
f
.
SetSheetRow
(
"Sheet3"
,
fmt
.
Sprintf
(
"A%d"
,
row
+
1
),
&
data
);
err
!=
nil
{
panic
(
err
)
}
}
return
f
}
stream.go
浏览文件 @
1666d045
...
...
@@ -167,7 +167,7 @@ func (sw *StreamWriter) Flush() error {
sheetDataByte
=
append
(
sheetDataByte
,
sw
.
SheetData
.
Bytes
()
...
)
replaceMap
:=
map
[
string
][]
byte
{
"XMLName"
:
[]
byte
{},
"XMLName"
:
{},
"SheetData"
:
sheetDataByte
,
}
sw
.
SheetData
.
Reset
()
...
...
table.go
浏览文件 @
1666d045
...
...
@@ -139,7 +139,7 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet
}
name
,
_
:=
f
.
GetCellValue
(
sheet
,
cell
)
if
_
,
err
:=
strconv
.
Atoi
(
name
);
err
==
nil
{
f
.
SetCellStr
(
sheet
,
cell
,
name
)
_
=
f
.
SetCellStr
(
sheet
,
cell
,
name
)
}
if
name
==
""
{
name
=
"Column"
+
strconv
.
Itoa
(
idx
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录