Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
13e0ed2a
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
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 搜索 >>
已验证
提交
13e0ed2a
编写于
11月 23, 2020
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed #735, refresh active tab after delete sheet
上级
599a8cb0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
15 deletion
+17
-15
cell.go
cell.go
+4
-5
sheet.go
sheet.go
+3
-9
sheet_test.go
sheet_test.go
+10
-1
未找到文件。
cell.go
浏览文件 @
13e0ed2a
...
...
@@ -765,21 +765,20 @@ func (f *File) formattedValue(s int, v string) string {
if
s
>=
len
(
styleSheet
.
CellXfs
.
Xf
)
{
return
v
}
numFmtI
d
:=
*
styleSheet
.
CellXfs
.
Xf
[
s
]
.
NumFmtID
ok
:=
builtInNumFmtFunc
[
numFmtI
d
]
numFmtI
D
:=
*
styleSheet
.
CellXfs
.
Xf
[
s
]
.
NumFmtID
ok
:=
builtInNumFmtFunc
[
numFmtI
D
]
if
ok
!=
nil
{
return
ok
(
v
,
builtInNumFmt
[
numFmtI
d
])
return
ok
(
v
,
builtInNumFmt
[
numFmtI
D
])
}
if
styleSheet
==
nil
||
styleSheet
.
NumFmts
==
nil
{
return
v
}
for
_
,
xlsxFmt
:=
range
styleSheet
.
NumFmts
.
NumFmt
{
if
xlsxFmt
.
NumFmtID
==
numFmtI
d
{
if
xlsxFmt
.
NumFmtID
==
numFmtI
D
{
format
:=
strings
.
ToLower
(
xlsxFmt
.
FormatCode
)
if
strings
.
Contains
(
format
,
"y"
)
||
strings
.
Contains
(
format
,
"m"
)
||
strings
.
Contains
(
strings
.
Replace
(
format
,
"red"
,
""
,
-
1
),
"d"
)
||
strings
.
Contains
(
format
,
"h"
)
{
return
parseTime
(
v
,
format
)
}
return
v
}
}
...
...
sheet.go
浏览文件 @
13e0ed2a
...
...
@@ -317,7 +317,7 @@ func (f *File) GetActiveSheetIndex() (index int) {
return
}
// getActiveSheetID provides a function to get active sheet
index
of the
// getActiveSheetID provides a function to get active sheet
ID
of the
// spreadsheet. If not found the active sheet will be return integer 0.
func
(
f
*
File
)
getActiveSheetID
()
int
{
wb
:=
f
.
workbookReader
()
...
...
@@ -499,6 +499,7 @@ func (f *File) DeleteSheet(name string) {
sheetName
:=
trimSheetName
(
name
)
wb
:=
f
.
workbookReader
()
wbRels
:=
f
.
relsReader
(
f
.
getWorkbookRelsPath
())
activeSheetName
:=
f
.
GetSheetName
(
f
.
GetActiveSheetIndex
())
for
idx
,
sheet
:=
range
wb
.
Sheets
.
Sheet
{
if
sheet
.
Name
==
sheetName
{
wb
.
Sheets
.
Sheet
=
append
(
wb
.
Sheets
.
Sheet
[
:
idx
],
wb
.
Sheets
.
Sheet
[
idx
+
1
:
]
...
)
...
...
@@ -526,14 +527,7 @@ func (f *File) DeleteSheet(name string) {
f
.
SheetCount
--
}
}
if
wb
.
BookViews
!=
nil
{
for
idx
,
bookView
:=
range
wb
.
BookViews
.
WorkBookView
{
if
bookView
.
ActiveTab
>=
f
.
SheetCount
{
wb
.
BookViews
.
WorkBookView
[
idx
]
.
ActiveTab
--
}
}
}
f
.
SetActiveSheet
(
len
(
f
.
GetSheetMap
()))
f
.
SetActiveSheet
(
f
.
GetSheetIndex
(
activeSheetName
))
}
// deleteSheetFromWorkbookRels provides a function to remove worksheet
...
...
sheet_test.go
浏览文件 @
13e0ed2a
...
...
@@ -359,6 +359,15 @@ func TestGetWorkbookRelsPath(t *testing.T) {
assert
.
Equal
(
t
,
"_rels/workbook.xml.rels"
,
f
.
getWorkbookRelsPath
())
}
func
TestDeleteSheet
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
f
.
SetActiveSheet
(
f
.
NewSheet
(
"Sheet2"
))
f
.
NewSheet
(
"Sheet3"
)
f
.
DeleteSheet
(
"Sheet1"
)
assert
.
Equal
(
t
,
"Sheet2"
,
f
.
GetSheetName
(
f
.
GetActiveSheetIndex
()))
assert
.
NoError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"TestDeleteSheet.xlsx"
)))
}
func
BenchmarkNewSheet
(
b
*
testing
.
B
)
{
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
...
...
@@ -380,9 +389,9 @@ func BenchmarkFile_SaveAs(b *testing.B) {
for
pb
.
Next
()
{
newSheetWithSave
()
}
})
}
func
newSheetWithSave
()
{
file
:=
NewFile
()
file
.
NewSheet
(
"sheet1"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录