Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
1cbb05d4
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,发现更多精彩内容 >>
已验证
提交
1cbb05d4
编写于
6月 28, 2020
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
GetCols support the row element without r attribute in the worksheet
上级
48f19f60
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
32 deletion
+46
-32
cell_test.go
cell_test.go
+3
-0
col.go
col.go
+35
-20
rows.go
rows.go
+8
-12
未找到文件。
cell_test.go
浏览文件 @
1cbb05d4
...
...
@@ -110,6 +110,9 @@ func TestGetCellValue(t *testing.T) {
assert
.
Equal
(
t
,
cell
,
value
)
assert
.
NoError
(
t
,
err
)
}
cols
,
err
:=
f
.
GetCols
(
"Sheet1"
)
assert
.
Equal
(
t
,
[][]
string
{{
""
,
""
,
"A3"
,
"A4"
,
""
,
""
,
"A7"
,
"A8"
},
{
""
,
""
,
""
,
"B4"
,
""
,
""
,
"B7"
,
"B8"
}},
cols
)
assert
.
NoError
(
t
,
err
)
}
func
TestGetCellFormula
(
t
*
testing
.
T
)
{
...
...
col.go
浏览文件 @
1cbb05d4
...
...
@@ -48,8 +48,8 @@ type Cols struct {
// return
// }
// for _, col := range cols {
// for _,
col
Cell := range col {
// fmt.Print
ln(col
Cell, "\t")
// for _,
row
Cell := range col {
// fmt.Print
(row
Cell, "\t")
// }
// fmt.Println()
// }
...
...
@@ -99,24 +99,34 @@ func (cols *Cols) Rows() ([]string, error) {
switch
startElement
:=
token
.
(
type
)
{
case
xml
.
StartElement
:
inElement
=
startElement
.
Name
.
Local
if
inElement
==
"row"
{
cellCol
=
0
cellRow
++
for
_
,
attr
:=
range
startElement
.
Attr
{
if
attr
.
Name
.
Local
==
"r"
{
cellRow
,
_
=
strconv
.
Atoi
(
attr
.
Value
)
}
}
}
if
inElement
==
"c"
{
cellCol
++
for
_
,
attr
:=
range
startElement
.
Attr
{
if
attr
.
Name
.
Local
==
"r"
{
if
cellCol
,
cellRow
,
err
=
CellNameToCoordinates
(
attr
.
Value
);
err
!=
nil
{
return
rows
,
err
}
blank
:=
cellRow
-
len
(
rows
)
for
i
:=
1
;
i
<
blank
;
i
++
{
rows
=
append
(
rows
,
""
)
}
if
cellCol
==
cols
.
curCol
{
colCell
:=
xlsxC
{}
_
=
decoder
.
DecodeElement
(
&
colCell
,
&
startElement
)
val
,
_
:=
colCell
.
getValueFrom
(
cols
.
f
,
d
)
rows
=
append
(
rows
,
val
)
}
}
}
blank
:=
cellRow
-
len
(
rows
)
for
i
:=
1
;
i
<
blank
;
i
++
{
rows
=
append
(
rows
,
""
)
}
if
cellCol
==
cols
.
curCol
{
colCell
:=
xlsxC
{}
_
=
decoder
.
DecodeElement
(
&
colCell
,
&
startElement
)
val
,
_
:=
colCell
.
getValueFrom
(
cols
.
f
,
d
)
rows
=
append
(
rows
,
val
)
}
}
}
}
...
...
@@ -152,10 +162,10 @@ func (f *File) Cols(sheet string) (*Cols, error) {
f
.
saveFileList
(
name
,
replaceRelationshipsNameSpaceBytes
(
output
))
}
var
(
inElement
string
cols
Cols
cellCol
int
err
error
inElement
string
cols
Cols
cellCol
,
curRow
,
row
int
err
error
)
cols
.
sheetXML
=
f
.
readXML
(
name
)
decoder
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
cols
.
sheetXML
))
...
...
@@ -168,25 +178,30 @@ func (f *File) Cols(sheet string) (*Cols, error) {
case
xml
.
StartElement
:
inElement
=
startElement
.
Name
.
Local
if
inElement
==
"row"
{
row
++
for
_
,
attr
:=
range
startElement
.
Attr
{
if
attr
.
Name
.
Local
==
"r"
{
if
c
ols
.
total
Row
,
err
=
strconv
.
Atoi
(
attr
.
Value
);
err
!=
nil
{
if
c
ur
Row
,
err
=
strconv
.
Atoi
(
attr
.
Value
);
err
!=
nil
{
return
&
cols
,
err
}
row
=
curRow
}
}
cols
.
totalRow
=
row
cellCol
=
0
}
if
inElement
==
"c"
{
cellCol
++
for
_
,
attr
:=
range
startElement
.
Attr
{
if
attr
.
Name
.
Local
==
"r"
{
if
cellCol
,
_
,
err
=
CellNameToCoordinates
(
attr
.
Value
);
err
!=
nil
{
return
&
cols
,
err
}
if
cellCol
>
cols
.
totalCol
{
cols
.
totalCol
=
cellCol
}
}
}
if
cellCol
>
cols
.
totalCol
{
cols
.
totalCol
=
cellCol
}
}
}
}
...
...
rows.go
浏览文件 @
1cbb05d4
...
...
@@ -32,7 +32,7 @@ import (
// }
// for _, row := range rows {
// for _, colCell := range row {
// fmt.Print
ln
(colCell, "\t")
// fmt.Print(colCell, "\t")
// }
// fmt.Println()
// }
...
...
@@ -111,6 +111,7 @@ func (rows *Rows) Columns() ([]string, error) {
}
}
if
inElement
==
"c"
{
cellCol
++
colCell
:=
xlsxC
{}
_
=
rows
.
decoder
.
DecodeElement
(
&
colCell
,
&
startElement
)
if
colCell
.
R
!=
""
{
...
...
@@ -118,8 +119,6 @@ func (rows *Rows) Columns() ([]string, error) {
if
err
!=
nil
{
return
columns
,
err
}
}
else
{
cellCol
++
}
blank
:=
cellCol
-
len
(
columns
)
for
i
:=
1
;
i
<
blank
;
i
++
{
...
...
@@ -177,10 +176,10 @@ func (f *File) Rows(sheet string) (*Rows, error) {
f
.
saveFileList
(
name
,
replaceRelationshipsNameSpaceBytes
(
output
))
}
var
(
err
error
inElement
string
row
,
curRow
int
rows
Rows
err
error
inElement
string
row
int
rows
Rows
)
decoder
:=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
f
.
readXML
(
name
)))
for
{
...
...
@@ -192,18 +191,15 @@ func (f *File) Rows(sheet string) (*Rows, error) {
case
xml
.
StartElement
:
inElement
=
startElement
.
Name
.
Local
if
inElement
==
"row"
{
row
++
for
_
,
attr
:=
range
startElement
.
Attr
{
if
attr
.
Name
.
Local
==
"r"
{
curR
ow
,
err
=
strconv
.
Atoi
(
attr
.
Value
)
r
ow
,
err
=
strconv
.
Atoi
(
attr
.
Value
)
if
err
!=
nil
{
return
&
rows
,
err
}
row
=
curRow
}
}
if
len
(
startElement
.
Attr
)
==
0
{
row
++
}
rows
.
totalRow
=
row
}
default
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录