Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
0f2a9053
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 搜索 >>
提交
0f2a9053
编写于
4月 02, 2020
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Performance improvements
上级
59f6af21
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
65 addition
and
20 deletion
+65
-20
adjust.go
adjust.go
+3
-2
drawing.go
drawing.go
+1
-1
excelize.go
excelize.go
+2
-3
lib.go
lib.go
+40
-2
lib_test.go
lib_test.go
+5
-0
picture.go
picture.go
+1
-1
rows.go
rows.go
+8
-6
sheet.go
sheet.go
+3
-3
sparkline.go
sparkline.go
+1
-1
stream.go
stream.go
+1
-1
未找到文件。
adjust.go
浏览文件 @
0f2a9053
...
...
@@ -80,9 +80,10 @@ func (f *File) adjustColDimensions(xlsx *xlsxWorksheet, col, offset int) {
// adjustRowDimensions provides a function to update row dimensions when
// inserting or deleting rows or columns.
func
(
f
*
File
)
adjustRowDimensions
(
xlsx
*
xlsxWorksheet
,
row
,
offset
int
)
{
for
i
,
r
:=
range
xlsx
.
SheetData
.
Row
{
for
i
:=
range
xlsx
.
SheetData
.
Row
{
r
:=
&
xlsx
.
SheetData
.
Row
[
i
]
if
newRow
:=
r
.
R
+
offset
;
r
.
R
>=
row
&&
newRow
>
0
{
f
.
ajustSingleRowDimensions
(
&
xlsx
.
SheetData
.
Row
[
i
]
,
newRow
)
f
.
ajustSingleRowDimensions
(
r
,
newRow
)
}
}
}
...
...
drawing.go
浏览文件 @
0f2a9053
...
...
@@ -1288,7 +1288,7 @@ func (f *File) deleteDrawing(col, row int, drawingXML, drawingType string) (err
}
for
idx
:=
0
;
idx
<
len
(
wsDr
.
TwoCellAnchor
);
idx
++
{
deTwoCellAnchor
=
new
(
decodeTwoCellAnchor
)
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
[]
byte
(
"<decodeTwoCellAnchor>"
+
wsDr
.
TwoCellAnchor
[
idx
]
.
GraphicFrame
+
"</decodeTwoCellAnchor>"
)))
.
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
stringToBytes
(
"<decodeTwoCellAnchor>"
+
wsDr
.
TwoCellAnchor
[
idx
]
.
GraphicFrame
+
"</decodeTwoCellAnchor>"
)))
.
Decode
(
deTwoCellAnchor
);
err
!=
nil
&&
err
!=
io
.
EOF
{
err
=
fmt
.
Errorf
(
"xml decode error: %s"
,
err
)
return
...
...
excelize.go
浏览文件 @
0f2a9053
...
...
@@ -234,10 +234,9 @@ func (f *File) addRels(relPath, relType, target, targetMode string) int {
// replaceRelationshipsNameSpaceBytes provides a function to replace
// XML tags to self-closing for compatible Microsoft Office Excel 2007.
func
replaceRelationshipsNameSpaceBytes
(
contentMarshal
[]
byte
)
[]
byte
{
var
oldXmlns
=
[]
byte
(
` xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`
)
var
oldXmlns
=
stringToBytes
(
` xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`
)
var
newXmlns
=
[]
byte
(
templateNamespaceIDMap
)
contentMarshal
=
bytes
.
Replace
(
contentMarshal
,
oldXmlns
,
newXmlns
,
-
1
)
return
contentMarshal
return
bytesReplace
(
contentMarshal
,
oldXmlns
,
newXmlns
,
-
1
)
}
// UpdateLinkedValue fix linked values within a spreadsheet are not updating in
...
...
lib.go
浏览文件 @
0f2a9053
...
...
@@ -17,6 +17,7 @@ import (
"log"
"strconv"
"strings"
"unsafe"
)
// ReadZipReader can be used to read an XLSX in memory without touching the
...
...
@@ -103,7 +104,7 @@ func JoinCellName(col string, row int) (string, error) {
if
row
<
1
{
return
""
,
newInvalidRowNumberError
(
row
)
}
return
fmt
.
Sprintf
(
"%s%d"
,
normCol
,
row
),
nil
return
normCol
+
strconv
.
Itoa
(
row
),
nil
}
// ColumnNameToNumber provides a function to convert Excel sheet column name
...
...
@@ -190,6 +191,7 @@ func CoordinatesToCellName(col, row int) (string, error) {
}
colname
,
err
:=
ColumnNumberToName
(
col
)
if
err
!=
nil
{
// Error should never happens here.
return
""
,
fmt
.
Errorf
(
"invalid cell coordinates [%d, %d]: %v"
,
col
,
row
,
err
)
}
return
fmt
.
Sprintf
(
"%s%d"
,
colname
,
row
),
nil
...
...
@@ -235,11 +237,47 @@ func namespaceStrictToTransitional(content []byte) []byte {
StrictNameSpaceSpreadSheet
:
NameSpaceSpreadSheet
,
}
for
s
,
n
:=
range
namespaceTranslationDic
{
content
=
bytes
.
Replace
(
content
,
[]
byte
(
s
),
[]
byte
(
n
),
-
1
)
content
=
bytes
Replace
(
content
,
stringToBytes
(
s
),
stringToBytes
(
n
),
-
1
)
}
return
content
}
// stringToBytes cast a string to bytes pointer and assign the value of this
// pointer.
func
stringToBytes
(
s
string
)
[]
byte
{
return
*
(
*
[]
byte
)(
unsafe
.
Pointer
(
&
s
))
}
// bytesReplace replace old bytes with given new.
func
bytesReplace
(
s
,
old
,
new
[]
byte
,
n
int
)
[]
byte
{
if
n
==
0
{
return
s
}
if
len
(
old
)
<
len
(
new
)
{
return
bytes
.
Replace
(
s
,
old
,
new
,
n
)
}
if
n
<
0
{
n
=
len
(
s
)
}
var
wid
,
i
,
j
,
w
int
for
i
,
j
=
0
,
0
;
i
<
len
(
s
)
&&
j
<
n
;
j
++
{
wid
=
bytes
.
Index
(
s
[
i
:
],
old
)
if
wid
<
0
{
break
}
w
+=
copy
(
s
[
w
:
],
s
[
i
:
i
+
wid
])
w
+=
copy
(
s
[
w
:
],
new
)
i
+=
wid
+
len
(
old
)
}
w
+=
copy
(
s
[
w
:
],
s
[
i
:
])
return
s
[
0
:
w
]
}
// genSheetPasswd provides a method to generate password for worksheet
// protection by given plaintext. When an Excel sheet is being protected with
// a password, a 16-bit (two byte) long hash is generated. To verify a
...
...
lib_test.go
浏览文件 @
0f2a9053
...
...
@@ -203,3 +203,8 @@ func TestCoordinatesToCellName_Error(t *testing.T) {
}
}
}
func
TestBytesReplace
(
t
*
testing
.
T
)
{
s
:=
[]
byte
{
0x01
}
assert
.
EqualValues
(
t
,
s
,
bytesReplace
(
s
,
[]
byte
{},
[]
byte
{},
0
))
}
picture.go
浏览文件 @
0f2a9053
...
...
@@ -510,7 +510,7 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
err
=
nil
for
_
,
anchor
:=
range
deWsDr
.
TwoCellAnchor
{
deTwoCellAnchor
=
new
(
decodeTwoCellAnchor
)
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
[]
byte
(
"<decodeTwoCellAnchor>"
+
anchor
.
Content
+
"</decodeTwoCellAnchor>"
)))
.
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
stringToBytes
(
"<decodeTwoCellAnchor>"
+
anchor
.
Content
+
"</decodeTwoCellAnchor>"
)))
.
Decode
(
deTwoCellAnchor
);
err
!=
nil
&&
err
!=
io
.
EOF
{
err
=
fmt
.
Errorf
(
"xml decode error: %s"
,
err
)
return
...
...
rows.go
浏览文件 @
0f2a9053
...
...
@@ -424,14 +424,16 @@ func (f *File) RemoveRow(sheet string, row int) error {
if
row
>
len
(
xlsx
.
SheetData
.
Row
)
{
return
f
.
adjustHelper
(
sheet
,
rows
,
row
,
-
1
)
}
for
rowIdx
:=
range
xlsx
.
SheetData
.
Row
{
if
xlsx
.
SheetData
.
Row
[
rowIdx
]
.
R
==
row
{
xlsx
.
SheetData
.
Row
=
append
(
xlsx
.
SheetData
.
Row
[
:
rowIdx
],
xlsx
.
SheetData
.
Row
[
rowIdx
+
1
:
]
...
)[
:
len
(
xlsx
.
SheetData
.
Row
)
-
1
]
return
f
.
adjustHelper
(
sheet
,
rows
,
row
,
-
1
)
keep
:=
0
for
rowIdx
:=
0
;
rowIdx
<
len
(
xlsx
.
SheetData
.
Row
);
rowIdx
++
{
v
:=
&
xlsx
.
SheetData
.
Row
[
rowIdx
]
if
v
.
R
!=
row
{
xlsx
.
SheetData
.
Row
[
keep
]
=
*
v
keep
++
}
}
return
nil
xlsx
.
SheetData
.
Row
=
xlsx
.
SheetData
.
Row
[
:
keep
]
return
f
.
adjustHelper
(
sheet
,
rows
,
row
,
-
1
)
}
// InsertRow provides a function to insert a new row after given Excel row
...
...
sheet.go
浏览文件 @
0f2a9053
...
...
@@ -206,9 +206,9 @@ func (f *File) setAppXML() {
// requirements about the structure of the input XML. This function is a
// horrible hack to fix that after the XML marshalling is completed.
func
replaceRelationshipsBytes
(
content
[]
byte
)
[]
byte
{
oldXmlns
:=
[]
byte
(
`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`
)
newXmlns
:=
[]
byte
(
"r"
)
return
bytes
.
Replace
(
content
,
oldXmlns
,
newXmlns
,
-
1
)
oldXmlns
:=
stringToBytes
(
`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`
)
newXmlns
:=
stringToBytes
(
"r"
)
return
bytesReplace
(
content
,
oldXmlns
,
newXmlns
,
-
1
)
}
// SetActiveSheet provides function to set default active worksheet of XLSX by
...
...
sparkline.go
浏览文件 @
0f2a9053
...
...
@@ -516,7 +516,7 @@ func (f *File) appendSparkline(ws *xlsxWorksheet, group *xlsxX14SparklineGroup,
for
idx
,
ext
=
range
decodeExtLst
.
Ext
{
if
ext
.
URI
==
ExtURISparklineGroups
{
decodeSparklineGroups
=
new
(
decodeX14SparklineGroups
)
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
[]
byte
(
ext
.
Content
)))
.
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
stringToBytes
(
ext
.
Content
)))
.
Decode
(
decodeSparklineGroups
);
err
!=
nil
&&
err
!=
io
.
EOF
{
return
}
...
...
stream.go
浏览文件 @
0f2a9053
...
...
@@ -365,7 +365,7 @@ func writeCell(buf *bufferedWriter, c xlsxC) {
buf
.
WriteString
(
`>`
)
if
c
.
V
!=
""
{
buf
.
WriteString
(
`<v>`
)
xml
.
EscapeText
(
buf
,
[]
byte
(
c
.
V
))
xml
.
EscapeText
(
buf
,
stringToBytes
(
c
.
V
))
buf
.
WriteString
(
`</v>`
)
}
buf
.
WriteString
(
`</c>`
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录