Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wx5575
excelize
提交
3325c394
excelize
项目概览
wx5575
/
excelize
与 Fork 源项目一致
Fork自
xuri / excelize
通知
1
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
3325c394
编写于
12月 06, 2021
作者:
D
Dokiy
提交者:
GitHub
12月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix adjustMergeCellsHelper and add some test cases (#1082)
Signed-off-by:
N
Dokiys
<
dokiychang@gmail.com
>
上级
7af55a54
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
233 addition
and
16 deletion
+233
-16
adjust.go
adjust.go
+30
-12
adjust_test.go
adjust_test.go
+203
-4
未找到文件。
adjust.go
浏览文件 @
3325c394
...
...
@@ -208,20 +208,23 @@ func (f *File) adjustMergeCells(ws *xlsxWorksheet, dir adjustDirection, num, off
if
y1
==
num
&&
y2
==
num
&&
offset
<
0
{
f
.
deleteMergeCell
(
ws
,
i
)
i
--
continue
}
y1
=
f
.
adjustMergeCellsHelper
(
y1
,
num
,
offset
)
y
2
=
f
.
adjustMergeCellsHelper
(
y2
,
num
,
offset
)
y
1
,
y2
=
f
.
adjustMergeCellsHelper
(
y1
,
y2
,
num
,
offset
)
}
else
{
if
x1
==
num
&&
x2
==
num
&&
offset
<
0
{
f
.
deleteMergeCell
(
ws
,
i
)
i
--
continue
}
x1
=
f
.
adjustMergeCellsHelper
(
x1
,
num
,
offset
)
x
2
=
f
.
adjustMergeCellsHelper
(
x2
,
num
,
offset
)
x
1
,
x2
=
f
.
adjustMergeCellsHelper
(
x1
,
x2
,
num
,
offset
)
}
if
x1
==
x2
&&
y1
==
y2
&&
i
>=
0
{
if
x1
==
x2
&&
y1
==
y2
{
f
.
deleteMergeCell
(
ws
,
i
)
i
--
continue
}
if
areaData
.
Ref
,
err
=
f
.
coordinatesToAreaRef
([]
int
{
x1
,
y1
,
x2
,
y2
});
err
!=
nil
{
return
err
...
...
@@ -233,19 +236,34 @@ func (f *File) adjustMergeCells(ws *xlsxWorksheet, dir adjustDirection, num, off
// adjustMergeCellsHelper provides a function for adjusting merge cells to
// compare and calculate cell axis by the given pivot, operation axis and
// offset.
func
(
f
*
File
)
adjustMergeCellsHelper
(
pivot
,
num
,
offset
int
)
int
{
if
pivot
>
num
{
pivot
+=
offset
if
pivot
<
1
{
return
1
func
(
f
*
File
)
adjustMergeCellsHelper
(
p1
,
p2
,
num
,
offset
int
)
(
int
,
int
)
{
if
p2
<
p1
{
p1
,
p2
=
p2
,
p1
}
if
offset
>=
0
{
if
num
<=
p1
{
p1
+=
offset
p2
+=
offset
}
else
if
num
<=
p2
{
p2
+=
offset
}
return
pivot
return
p1
,
p2
}
if
num
<
p1
||
(
num
==
p1
&&
num
==
p2
)
{
p1
+=
offset
p2
+=
offset
}
else
if
num
<=
p2
{
p2
+=
offset
}
return
p
ivot
return
p
1
,
p2
}
// deleteMergeCell provides a function to delete merged cell by given index.
func
(
f
*
File
)
deleteMergeCell
(
ws
*
xlsxWorksheet
,
idx
int
)
{
if
idx
<
0
{
return
}
if
len
(
ws
.
MergeCells
.
Cells
)
>
idx
{
ws
.
MergeCells
.
Cells
=
append
(
ws
.
MergeCells
.
Cells
[
:
idx
],
ws
.
MergeCells
.
Cells
[
idx
+
1
:
]
...
)
ws
.
MergeCells
.
Count
=
len
(
ws
.
MergeCells
.
Cells
)
...
...
adjust_test.go
浏览文件 @
3325c394
...
...
@@ -45,6 +45,209 @@ func TestAdjustMergeCells(t *testing.T) {
},
},
},
columns
,
1
,
-
1
))
// testing adjustMergeCells
var
cases
[]
struct
{
lable
string
ws
*
xlsxWorksheet
dir
adjustDirection
num
int
offset
int
expect
string
}
// testing insert
cases
=
[]
struct
{
lable
string
ws
*
xlsxWorksheet
dir
adjustDirection
num
int
offset
int
expect
string
}{
{
lable
:
"insert row on ref"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
rows
,
num
:
2
,
offset
:
1
,
expect
:
"A3:B4"
,
},
{
lable
:
"insert row on bottom of ref"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
rows
,
num
:
3
,
offset
:
1
,
expect
:
"A2:B4"
,
},
{
lable
:
"insert column on the left"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
columns
,
num
:
1
,
offset
:
1
,
expect
:
"B2:C3"
,
},
}
for
_
,
c
:=
range
cases
{
assert
.
NoError
(
t
,
f
.
adjustMergeCells
(
c
.
ws
,
c
.
dir
,
c
.
num
,
1
))
assert
.
Equal
(
t
,
c
.
expect
,
c
.
ws
.
MergeCells
.
Cells
[
0
]
.
Ref
,
c
.
lable
)
}
// testing delete
cases
=
[]
struct
{
lable
string
ws
*
xlsxWorksheet
dir
adjustDirection
num
int
offset
int
expect
string
}{
{
lable
:
"delete row on top of ref"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
rows
,
num
:
2
,
offset
:
-
1
,
expect
:
"A2:B2"
,
},
{
lable
:
"delete row on bottom of ref"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
rows
,
num
:
3
,
offset
:
-
1
,
expect
:
"A2:B2"
,
},
{
lable
:
"delete column on the ref left"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
columns
,
num
:
1
,
offset
:
-
1
,
expect
:
"A2:A3"
,
},
{
lable
:
"delete column on the ref right"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A2:B3"
,
},
},
},
},
dir
:
columns
,
num
:
2
,
offset
:
-
1
,
expect
:
"A2:A3"
,
},
}
for
_
,
c
:=
range
cases
{
assert
.
NoError
(
t
,
f
.
adjustMergeCells
(
c
.
ws
,
c
.
dir
,
c
.
num
,
-
1
))
assert
.
Equal
(
t
,
c
.
expect
,
c
.
ws
.
MergeCells
.
Cells
[
0
]
.
Ref
,
c
.
lable
)
}
// testing delete one row/column
cases
=
[]
struct
{
lable
string
ws
*
xlsxWorksheet
dir
adjustDirection
num
int
offset
int
expect
string
}{
{
lable
:
"delete one row ref"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A1:B1"
,
},
},
},
},
dir
:
rows
,
num
:
1
,
offset
:
-
1
,
},
{
lable
:
"delete one column ref"
,
ws
:
&
xlsxWorksheet
{
MergeCells
:
&
xlsxMergeCells
{
Cells
:
[]
*
xlsxMergeCell
{
{
Ref
:
"A1:A2"
,
},
},
},
},
dir
:
columns
,
num
:
1
,
offset
:
-
1
,
},
}
for
_
,
c
:=
range
cases
{
assert
.
NoError
(
t
,
f
.
adjustMergeCells
(
c
.
ws
,
c
.
dir
,
c
.
num
,
-
1
))
assert
.
Equal
(
t
,
0
,
len
(
c
.
ws
.
MergeCells
.
Cells
),
c
.
lable
)
}
f
=
NewFile
()
p1
,
p2
:=
f
.
adjustMergeCellsHelper
(
2
,
1
,
0
,
0
)
assert
.
Equal
(
t
,
1
,
p1
)
assert
.
Equal
(
t
,
2
,
p2
)
f
.
deleteMergeCell
(
nil
,
-
1
)
}
func
TestAdjustAutoFilter
(
t
*
testing
.
T
)
{
...
...
@@ -84,10 +287,6 @@ func TestAdjustHelper(t *testing.T) {
assert
.
EqualError
(
t
,
f
.
adjustHelper
(
"SheetN"
,
rows
,
0
,
0
),
"sheet SheetN is not exist"
)
}
func
TestAdjustMergeCellsHelper
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
1
,
NewFile
()
.
adjustMergeCellsHelper
(
1
,
0
,
-
2
))
}
func
TestAdjustCalcChain
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
CalcChain
=
&
xlsxCalcChain
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录