Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
3012df08
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,发现更多精彩内容 >>
提交
3012df08
编写于
12月 19, 2018
作者:
S
sairoutine
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add GetMergeCells
上级
ce5b37a4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
0 deletion
+93
-0
excelize.go
excelize.go
+40
-0
excelize_test.go
excelize_test.go
+53
-0
test/MergeCell.xlsx
test/MergeCell.xlsx
+0
-0
未找到文件。
excelize.go
浏览文件 @
3012df08
...
...
@@ -401,3 +401,43 @@ func (f *File) adjustAutoFilterHelper(xlsx *xlsxWorksheet, column, rowIndex, off
}
}
}
// GetMergeCells provides a function to get all merged cells from a worksheet currently.
func
(
f
*
File
)
GetMergeCells
(
sheet
string
)
[]
MergeCell
{
mergeCells
:=
[]
MergeCell
{}
xlsx
:=
f
.
workSheetReader
(
sheet
)
if
xlsx
.
MergeCells
!=
nil
{
for
i
:=
0
;
i
<
len
(
xlsx
.
MergeCells
.
Cells
);
i
++
{
ref
:=
xlsx
.
MergeCells
.
Cells
[
i
]
.
Ref
axis
:=
strings
.
Split
(
ref
,
":"
)[
0
]
mergeCells
=
append
(
mergeCells
,
[]
string
{
ref
,
f
.
GetCellValue
(
sheet
,
axis
)})
}
}
return
mergeCells
}
// MergeCell define a merged cell data.
// It consists of the following structure.
// example: []string{"D4:E10", "cell value"}
type
MergeCell
[]
string
// GetCellValue returns merged cell value.
func
(
m
*
MergeCell
)
GetCellValue
()
string
{
return
(
*
m
)[
1
]
}
// GetStartAxis returns the merge start axis.
// example: "C2"
func
(
m
*
MergeCell
)
GetStartAxis
()
string
{
axis
:=
strings
.
Split
((
*
m
)[
0
],
":"
)
return
axis
[
0
]
}
// GetEndAxis returns the merge end axis.
// example: "D4"
func
(
m
*
MergeCell
)
GetEndAxis
()
string
{
axis
:=
strings
.
Split
((
*
m
)[
0
],
":"
)
return
axis
[
1
]
}
excelize_test.go
浏览文件 @
3012df08
...
...
@@ -351,6 +351,59 @@ func TestMergeCell(t *testing.T) {
}
}
func
TestGetMergeCells
(
t
*
testing
.
T
)
{
wants
:=
[]
struct
{
value
string
start
string
end
string
}{
{
value
:
"A1"
,
start
:
"A1"
,
end
:
"B1"
,
},
{
value
:
"A2"
,
start
:
"A2"
,
end
:
"A3"
,
},
{
value
:
"A4"
,
start
:
"A4"
,
end
:
"B5"
,
},
{
value
:
"A7"
,
start
:
"A7"
,
end
:
"C10"
,
},
}
xlsx
,
err
:=
OpenFile
(
"./test/MergeCell.xlsx"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
mergeCells
:=
xlsx
.
GetMergeCells
(
"Sheet1"
)
if
len
(
mergeCells
)
!=
len
(
wants
)
{
t
.
Fatalf
(
"Expected count of merge cells %d, but got %d
\n
"
,
len
(
wants
),
len
(
mergeCells
))
}
for
i
,
m
:=
range
mergeCells
{
if
wants
[
i
]
.
value
!=
m
.
GetCellValue
()
{
t
.
Fatalf
(
"Expected merged cell value %s, but got %s
\n
"
,
wants
[
i
]
.
value
,
m
.
GetCellValue
())
}
if
wants
[
i
]
.
start
!=
m
.
GetStartAxis
()
{
t
.
Fatalf
(
"Expected merged cell value %s, but got %s
\n
"
,
wants
[
i
]
.
start
,
m
.
GetStartAxis
())
}
if
wants
[
i
]
.
end
!=
m
.
GetEndAxis
()
{
t
.
Fatalf
(
"Expected merged cell value %s, but got %s
\n
"
,
wants
[
i
]
.
end
,
m
.
GetEndAxis
())
}
}
}
func
TestSetCellStyleAlignment
(
t
*
testing
.
T
)
{
xlsx
,
err
:=
OpenFile
(
"./test/Book2.xlsx"
)
if
err
!=
nil
{
...
...
test/MergeCell.xlsx
0 → 100644
浏览文件 @
3012df08
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录