Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
3648335d
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 搜索 >>
提交
3648335d
编写于
2月 11, 2021
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
This improves compatibility for worksheet relative XML path and multi rules auto filter
上级
3783d1d0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
22 deletion
+22
-22
sheet.go
sheet.go
+9
-9
stream_test.go
stream_test.go
+1
-1
table.go
table.go
+8
-8
xmlTable.go
xmlTable.go
+4
-4
未找到文件。
sheet.go
浏览文件 @
3648335d
...
...
@@ -447,17 +447,17 @@ func (f *File) GetSheetList() (list []string) {
// getSheetMap provides a function to get worksheet name and XML file path map
// of the spreadsheet.
func
(
f
*
File
)
getSheetMap
()
map
[
string
]
string
{
content
:=
f
.
workbookReader
()
rels
:=
f
.
relsReader
(
f
.
getWorkbookRelsPath
())
maps
:=
map
[
string
]
string
{}
for
_
,
v
:=
range
content
.
Sheets
.
Sheet
{
for
_
,
rel
:=
range
rels
.
Relationships
{
for
_
,
v
:=
range
f
.
workbookReader
()
.
Sheets
.
Sheet
{
for
_
,
rel
:=
range
f
.
relsReader
(
f
.
getWorkbookRelsPath
())
.
Relationships
{
if
rel
.
ID
==
v
.
ID
{
// Construct a target XML as xl/worksheets/sheet%d by split path, compatible with different types of relative paths in workbook.xml.rels, for example: worksheets/sheet%d.xml and /xl/worksheets/sheet%d.xml
pathInfo
:=
strings
.
Split
(
rel
.
Target
,
"/"
)
pathInfoLen
:=
len
(
pathInfo
)
if
pathInfoLen
>
1
{
maps
[
v
.
Name
]
=
fmt
.
Sprintf
(
"xl/%s"
,
strings
.
Join
(
pathInfo
[
pathInfoLen
-
2
:
],
"/"
))
// Construct a target XML as xl/worksheets/sheet%d by split
// path, compatible with different types of relative paths in
// workbook.xml.rels, for example: worksheets/sheet%d.xml
// and /xl/worksheets/sheet%d.xml
path
:=
filepath
.
ToSlash
(
strings
.
TrimPrefix
(
filepath
.
Clean
(
fmt
.
Sprintf
(
"%s/%s"
,
filepath
.
Dir
(
f
.
getWorkbookPath
()),
rel
.
Target
)),
"/"
))
if
_
,
ok
:=
f
.
XLSX
[
path
];
ok
{
maps
[
v
.
Name
]
=
path
}
}
}
...
...
stream_test.go
浏览文件 @
3648335d
...
...
@@ -76,7 +76,7 @@ func TestStreamWriter(t *testing.T) {
file
=
NewFile
()
streamWriter
,
err
=
file
.
NewStreamWriter
(
"Sheet1"
)
assert
.
NoError
(
t
,
err
)
for
rowID
:=
10
;
rowID
<=
512
00
;
rowID
++
{
for
rowID
:=
10
;
rowID
<=
256
00
;
rowID
++
{
row
:=
make
([]
interface
{},
50
)
for
colID
:=
0
;
colID
<
50
;
colID
++
{
row
[
colID
]
=
rand
.
Intn
(
640000
)
...
...
table.go
浏览文件 @
3648335d
...
...
@@ -348,9 +348,9 @@ func (f *File) autoFilter(sheet, ref string, refRange, col int, formatSet *forma
return
fmt
.
Errorf
(
"incorrect index of column '%s'"
,
formatSet
.
Column
)
}
filter
.
FilterColumn
=
&
xlsxFilterColumn
{
filter
.
FilterColumn
=
append
(
filter
.
FilterColumn
,
&
xlsxFilterColumn
{
ColID
:
offset
,
}
}
)
re
:=
regexp
.
MustCompile
(
`"(?:[^"]|"")*"|\S+`
)
token
:=
re
.
FindAllString
(
formatSet
.
Expression
,
-
1
)
if
len
(
token
)
!=
3
&&
len
(
token
)
!=
7
{
...
...
@@ -372,14 +372,14 @@ func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []strin
// Single equality.
var
filters
[]
*
xlsxFilter
filters
=
append
(
filters
,
&
xlsxFilter
{
Val
:
tokens
[
0
]})
filter
.
FilterColumn
.
Filters
=
&
xlsxFilters
{
Filter
:
filters
}
filter
.
FilterColumn
[
0
]
.
Filters
=
&
xlsxFilters
{
Filter
:
filters
}
}
else
if
len
(
exp
)
==
3
&&
exp
[
0
]
==
2
&&
exp
[
1
]
==
1
&&
exp
[
2
]
==
2
{
// Double equality with "or" operator.
filters
:=
[]
*
xlsxFilter
{}
for
_
,
v
:=
range
tokens
{
filters
=
append
(
filters
,
&
xlsxFilter
{
Val
:
v
})
}
filter
.
FilterColumn
.
Filters
=
&
xlsxFilters
{
Filter
:
filters
}
filter
.
FilterColumn
[
0
]
.
Filters
=
&
xlsxFilters
{
Filter
:
filters
}
}
else
{
// Non default custom filter.
expRel
:=
map
[
int
]
int
{
0
:
0
,
1
:
2
}
...
...
@@ -387,7 +387,7 @@ func (f *File) writeAutoFilter(filter *xlsxAutoFilter, exp []int, tokens []strin
for
k
,
v
:=
range
tokens
{
f
.
writeCustomFilter
(
filter
,
exp
[
expRel
[
k
]],
v
)
if
k
==
1
{
filter
.
FilterColumn
.
CustomFilters
.
And
=
andRel
[
exp
[
k
]]
filter
.
FilterColumn
[
0
]
.
CustomFilters
.
And
=
andRel
[
exp
[
k
]]
}
}
}
...
...
@@ -408,12 +408,12 @@ func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val strin
Operator
:
operators
[
operator
],
Val
:
val
,
}
if
filter
.
FilterColumn
.
CustomFilters
!=
nil
{
filter
.
FilterColumn
.
CustomFilters
.
CustomFilter
=
append
(
filter
.
FilterColumn
.
CustomFilters
.
CustomFilter
,
&
customFilter
)
if
filter
.
FilterColumn
[
0
]
.
CustomFilters
!=
nil
{
filter
.
FilterColumn
[
0
]
.
CustomFilters
.
CustomFilter
=
append
(
filter
.
FilterColumn
[
0
]
.
CustomFilters
.
CustomFilter
,
&
customFilter
)
}
else
{
customFilters
:=
[]
*
xlsxCustomFilter
{}
customFilters
=
append
(
customFilters
,
&
customFilter
)
filter
.
FilterColumn
.
CustomFilters
=
&
xlsxCustomFilters
{
CustomFilter
:
customFilters
}
filter
.
FilterColumn
[
0
]
.
CustomFilters
=
&
xlsxCustomFilters
{
CustomFilter
:
customFilters
}
}
}
...
...
xmlTable.go
浏览文件 @
3648335d
// Copyright 2016 - 202
0
The excelize Authors. All rights reserved. Use of
// Copyright 2016 - 202
1
The excelize Authors. All rights reserved. Use of
// this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//
...
...
@@ -46,9 +46,9 @@ type xlsxTable struct {
// applied column by column to a table of data in the worksheet. This collection
// expresses AutoFilter settings.
type
xlsxAutoFilter
struct
{
XMLName
xml
.
Name
`xml:"autoFilter"`
Ref
string
`xml:"ref,attr"`
FilterColumn
*
xlsxFilterColumn
`xml:"filterColumn"`
XMLName
xml
.
Name
`xml:"autoFilter"`
Ref
string
`xml:"ref,attr"`
FilterColumn
[]
*
xlsxFilterColumn
`xml:"filterColumn"`
}
// xlsxFilterColumn directly maps the filterColumn element. The filterColumn
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录