Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
2ae63137
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,发现更多精彩内容 >>
已验证
提交
2ae63137
编写于
5月 29, 2020
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add limits for total columns, row and filename length
上级
c168233e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
29 addition
and
7 deletion
+29
-7
cell.go
cell.go
+5
-5
excelize_test.go
excelize_test.go
+1
-0
file.go
file.go
+4
-0
lib.go
lib.go
+6
-1
lib_test.go
lib_test.go
+4
-1
xmlDrawing.go
xmlDrawing.go
+9
-0
未找到文件。
cell.go
浏览文件 @
2ae63137
...
@@ -281,8 +281,8 @@ func (f *File) SetCellStr(sheet, axis, value string) error {
...
@@ -281,8 +281,8 @@ func (f *File) SetCellStr(sheet, axis, value string) error {
// setCellString provides a function to set string type to shared string
// setCellString provides a function to set string type to shared string
// table.
// table.
func
(
f
*
File
)
setCellString
(
value
string
)
(
t
string
,
v
string
,
ns
xml
.
Attr
)
{
func
(
f
*
File
)
setCellString
(
value
string
)
(
t
string
,
v
string
,
ns
xml
.
Attr
)
{
if
len
(
value
)
>
32767
{
if
len
(
value
)
>
TotalCellChars
{
value
=
value
[
0
:
32767
]
value
=
value
[
0
:
TotalCellChars
]
}
}
// Leading and ending space(s) character detection.
// Leading and ending space(s) character detection.
if
len
(
value
)
>
0
&&
(
value
[
0
]
==
32
||
value
[
len
(
value
)
-
1
]
==
32
)
{
if
len
(
value
)
>
0
&&
(
value
[
0
]
==
32
||
value
[
len
(
value
)
-
1
]
==
32
)
{
...
@@ -311,8 +311,8 @@ func (f *File) setSharedString(val string) int {
...
@@ -311,8 +311,8 @@ func (f *File) setSharedString(val string) int {
// setCellStr provides a function to set string type to cell.
// setCellStr provides a function to set string type to cell.
func
setCellStr
(
value
string
)
(
t
string
,
v
string
,
ns
xml
.
Attr
)
{
func
setCellStr
(
value
string
)
(
t
string
,
v
string
,
ns
xml
.
Attr
)
{
if
len
(
value
)
>
32767
{
if
len
(
value
)
>
TotalCellChars
{
value
=
value
[
0
:
32767
]
value
=
value
[
0
:
TotalCellChars
]
}
}
// Leading and ending space(s) character detection.
// Leading and ending space(s) character detection.
if
len
(
value
)
>
0
&&
(
value
[
0
]
==
32
||
value
[
len
(
value
)
-
1
]
==
32
)
{
if
len
(
value
)
>
0
&&
(
value
[
0
]
==
32
||
value
[
len
(
value
)
-
1
]
==
32
)
{
...
@@ -476,7 +476,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
...
@@ -476,7 +476,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
xlsx
.
Hyperlinks
=
new
(
xlsxHyperlinks
)
xlsx
.
Hyperlinks
=
new
(
xlsxHyperlinks
)
}
}
if
len
(
xlsx
.
Hyperlinks
.
Hyperlink
)
>
65529
{
if
len
(
xlsx
.
Hyperlinks
.
Hyperlink
)
>
TotalSheetHyperlinks
{
return
errors
.
New
(
"over maximum limit hyperlinks in a worksheet"
)
return
errors
.
New
(
"over maximum limit hyperlinks in a worksheet"
)
}
}
...
...
excelize_test.go
浏览文件 @
2ae63137
...
@@ -166,6 +166,7 @@ func TestOpenFile(t *testing.T) {
...
@@ -166,6 +166,7 @@ func TestOpenFile(t *testing.T) {
assert
.
NoError
(
t
,
f
.
SetCellStr
(
"Sheet2"
,
"c"
+
strconv
.
Itoa
(
i
),
strconv
.
Itoa
(
i
)))
assert
.
NoError
(
t
,
f
.
SetCellStr
(
"Sheet2"
,
"c"
+
strconv
.
Itoa
(
i
),
strconv
.
Itoa
(
i
)))
}
}
assert
.
NoError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"TestOpenFile.xlsx"
)))
assert
.
NoError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"TestOpenFile.xlsx"
)))
assert
.
EqualError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
strings
.
Repeat
(
"c"
,
199
),
".xlsx"
)),
"file name length exceeds maximum limit"
)
}
}
func
TestSaveFile
(
t
*
testing
.
T
)
{
func
TestSaveFile
(
t
*
testing
.
T
)
{
...
...
file.go
浏览文件 @
2ae63137
...
@@ -12,6 +12,7 @@ package excelize
...
@@ -12,6 +12,7 @@ package excelize
import
(
import
(
"archive/zip"
"archive/zip"
"bytes"
"bytes"
"errors"
"fmt"
"fmt"
"io"
"io"
"os"
"os"
...
@@ -62,6 +63,9 @@ func (f *File) Save() error {
...
@@ -62,6 +63,9 @@ func (f *File) Save() error {
// SaveAs provides a function to create or update to an xlsx file at the
// SaveAs provides a function to create or update to an xlsx file at the
// provided path.
// provided path.
func
(
f
*
File
)
SaveAs
(
name
string
)
error
{
func
(
f
*
File
)
SaveAs
(
name
string
)
error
{
if
len
(
name
)
>
FileNameLength
{
return
errors
.
New
(
"file name length exceeds maximum limit"
)
}
file
,
err
:=
os
.
OpenFile
(
name
,
os
.
O_WRONLY
|
os
.
O_TRUNC
|
os
.
O_CREATE
,
0666
)
file
,
err
:=
os
.
OpenFile
(
name
,
os
.
O_WRONLY
|
os
.
O_TRUNC
|
os
.
O_CREATE
,
0666
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
lib.go
浏览文件 @
2ae63137
...
@@ -135,6 +135,9 @@ func ColumnNameToNumber(name string) (int, error) {
...
@@ -135,6 +135,9 @@ func ColumnNameToNumber(name string) (int, error) {
}
}
multi
*=
26
multi
*=
26
}
}
if
col
>
TotalColumns
{
return
-
1
,
fmt
.
Errorf
(
"column number exceeds maximum limit"
)
}
return
col
,
nil
return
col
,
nil
}
}
...
@@ -172,7 +175,9 @@ func CellNameToCoordinates(cell string) (int, int, error) {
...
@@ -172,7 +175,9 @@ func CellNameToCoordinates(cell string) (int, int, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
-
1
,
fmt
.
Errorf
(
msg
,
cell
,
err
)
return
-
1
,
-
1
,
fmt
.
Errorf
(
msg
,
cell
,
err
)
}
}
if
row
>
TotalRows
{
return
-
1
,
-
1
,
fmt
.
Errorf
(
"row number exceeds maximum limit"
)
}
col
,
err
:=
ColumnNameToNumber
(
colname
)
col
,
err
:=
ColumnNameToNumber
(
colname
)
return
col
,
row
,
err
return
col
,
row
,
err
}
}
...
...
lib_test.go
浏览文件 @
2ae63137
...
@@ -23,7 +23,6 @@ var validColumns = []struct {
...
@@ -23,7 +23,6 @@ var validColumns = []struct {
{
Name
:
"AZ"
,
Num
:
26
+
26
},
{
Name
:
"AZ"
,
Num
:
26
+
26
},
{
Name
:
"ZZ"
,
Num
:
26
+
26
*
26
},
{
Name
:
"ZZ"
,
Num
:
26
+
26
*
26
},
{
Name
:
"AAA"
,
Num
:
26
+
26
*
26
+
1
},
{
Name
:
"AAA"
,
Num
:
26
+
26
*
26
+
1
},
{
Name
:
"ZZZ"
,
Num
:
26
+
26
*
26
+
26
*
26
*
26
},
}
}
var
invalidColumns
=
[]
struct
{
var
invalidColumns
=
[]
struct
{
...
@@ -72,6 +71,8 @@ func TestColumnNameToNumber_Error(t *testing.T) {
...
@@ -72,6 +71,8 @@ func TestColumnNameToNumber_Error(t *testing.T) {
assert
.
Equalf
(
t
,
col
.
Num
,
out
,
msg
,
col
.
Name
)
assert
.
Equalf
(
t
,
col
.
Num
,
out
,
msg
,
col
.
Name
)
}
}
}
}
_
,
err
:=
ColumnNameToNumber
(
"XFE"
)
assert
.
EqualError
(
t
,
err
,
"column number exceeds maximum limit"
)
}
}
func
TestColumnNumberToName_OK
(
t
*
testing
.
T
)
{
func
TestColumnNumberToName_OK
(
t
*
testing
.
T
)
{
...
@@ -172,6 +173,8 @@ func TestCellNameToCoordinates_Error(t *testing.T) {
...
@@ -172,6 +173,8 @@ func TestCellNameToCoordinates_Error(t *testing.T) {
assert
.
Equalf
(
t
,
-
1
,
r
,
msg
,
cell
)
assert
.
Equalf
(
t
,
-
1
,
r
,
msg
,
cell
)
}
}
}
}
_
,
_
,
err
:=
CellNameToCoordinates
(
"A1048577"
)
assert
.
EqualError
(
t
,
err
,
"row number exceeds maximum limit"
)
}
}
func
TestCoordinatesToCellName_OK
(
t
*
testing
.
T
)
{
func
TestCoordinatesToCellName_OK
(
t
*
testing
.
T
)
{
...
...
xmlDrawing.go
浏览文件 @
2ae63137
...
@@ -80,6 +80,15 @@ const (
...
@@ -80,6 +80,15 @@ const (
ExtURIMacExcelMX
=
"{64002731-A6B0-56B0-2670-7721B7C09600}"
ExtURIMacExcelMX
=
"{64002731-A6B0-56B0-2670-7721B7C09600}"
)
)
// Excel specifications and limits
const
(
FileNameLength
=
207
TotalRows
=
1048576
TotalColumns
=
16384
TotalSheetHyperlinks
=
65529
TotalCellChars
=
32767
)
var
supportImageTypes
=
map
[
string
]
string
{
".gif"
:
".gif"
,
".jpg"
:
".jpeg"
,
".jpeg"
:
".jpeg"
,
".png"
:
".png"
,
".tif"
:
".tiff"
,
".tiff"
:
".tiff"
}
var
supportImageTypes
=
map
[
string
]
string
{
".gif"
:
".gif"
,
".jpg"
:
".jpeg"
,
".jpeg"
:
".jpeg"
,
".png"
:
".png"
,
".tif"
:
".tiff"
,
".tiff"
:
".tiff"
}
// xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This
// xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录