Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
5c99300e
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,发现更多精彩内容 >>
已验证
提交
5c99300e
编写于
5月 26, 2020
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #622, storage string to SST (shared string table)
上级
1aeb8182
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
12 deletion
+46
-12
cell.go
cell.go
+35
-11
rows.go
rows.go
+10
-0
xmlSharedStrings.go
xmlSharedStrings.go
+1
-1
未找到文件。
cell.go
浏览文件 @
5c99300e
...
...
@@ -274,10 +274,43 @@ func (f *File) SetCellStr(sheet, axis, value string) error {
return
err
}
cellData
.
S
=
f
.
prepareCellStyle
(
xlsx
,
col
,
cellData
.
S
)
cellData
.
T
,
cellData
.
V
,
cellData
.
XMLSpace
=
setCellStr
(
value
)
cellData
.
T
,
cellData
.
V
,
cellData
.
XMLSpace
=
f
.
setCellString
(
value
)
return
err
}
// setCellString provides a function to set string type to shared string
// table.
func
(
f
*
File
)
setCellString
(
value
string
)
(
t
string
,
v
string
,
ns
xml
.
Attr
)
{
if
len
(
value
)
>
32767
{
value
=
value
[
0
:
32767
]
}
// Leading and ending space(s) character detection.
if
len
(
value
)
>
0
&&
(
value
[
0
]
==
32
||
value
[
len
(
value
)
-
1
]
==
32
)
{
ns
=
xml
.
Attr
{
Name
:
xml
.
Name
{
Space
:
NameSpaceXML
,
Local
:
"space"
},
Value
:
"preserve"
,
}
}
t
=
"s"
v
=
strconv
.
Itoa
(
f
.
setSharedString
(
value
))
return
}
// setSharedString provides a function to add string to the share string table.
func
(
f
*
File
)
setSharedString
(
val
string
)
int
{
sst
:=
f
.
sharedStringsReader
()
for
i
,
si
:=
range
sst
.
SI
{
if
si
.
T
==
val
{
return
i
}
}
sst
.
Count
++
sst
.
UniqueCount
++
sst
.
SI
=
append
(
sst
.
SI
,
xlsxSI
{
T
:
val
})
return
sst
.
UniqueCount
-
1
}
// setCellStr provides a function to set string type to cell.
func
setCellStr
(
value
string
)
(
t
string
,
v
string
,
ns
xml
.
Attr
)
{
if
len
(
value
)
>
32767
{
value
=
value
[
0
:
32767
]
...
...
@@ -590,7 +623,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
for
_
,
textRun
:=
range
runs
{
run
:=
xlsxR
{
T
:
&
xlsxT
{
Val
:
textRun
.
Text
}}
if
strings
.
ContainsAny
(
textRun
.
Text
,
"
\r\n
"
)
{
run
.
T
.
Space
=
"preserve"
run
.
T
.
Space
=
xml
.
Attr
{
Name
:
xml
.
Name
{
Space
:
NameSpaceXML
,
Local
:
"space"
},
Value
:
"preserve"
}
}
fnt
:=
textRun
.
Font
if
fnt
!=
nil
{
...
...
@@ -625,15 +658,6 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
sst
.
Count
++
sst
.
UniqueCount
++
cellData
.
T
,
cellData
.
V
=
"s"
,
strconv
.
Itoa
(
len
(
sst
.
SI
)
-
1
)
f
.
addContentTypePart
(
0
,
"sharedStrings"
)
rels
:=
f
.
relsReader
(
"xl/_rels/workbook.xml.rels"
)
for
_
,
rel
:=
range
rels
.
Relationships
{
if
rel
.
Target
==
"sharedStrings.xml"
{
return
err
}
}
// Update xl/_rels/workbook.xml.rels
f
.
addRels
(
"xl/_rels/workbook.xml.rels"
,
SourceRelationshipSharedStrings
,
"sharedStrings.xml"
,
""
)
return
err
}
...
...
rows.go
浏览文件 @
5c99300e
...
...
@@ -285,12 +285,22 @@ func (f *File) sharedStringsReader() *xlsxSST {
ss
:=
f
.
readXML
(
"xl/sharedStrings.xml"
)
if
len
(
ss
)
==
0
{
ss
=
f
.
readXML
(
"xl/SharedStrings.xml"
)
delete
(
f
.
XLSX
,
"xl/SharedStrings.xml"
)
}
if
err
=
f
.
xmlNewDecoder
(
bytes
.
NewReader
(
namespaceStrictToTransitional
(
ss
)))
.
Decode
(
&
sharedStrings
);
err
!=
nil
&&
err
!=
io
.
EOF
{
log
.
Printf
(
"xml decode error: %s"
,
err
)
}
f
.
SharedStrings
=
&
sharedStrings
f
.
addContentTypePart
(
0
,
"sharedStrings"
)
rels
:=
f
.
relsReader
(
"xl/_rels/workbook.xml.rels"
)
for
_
,
rel
:=
range
rels
.
Relationships
{
if
rel
.
Target
==
"sharedStrings.xml"
{
return
f
.
SharedStrings
}
}
// Update xl/_rels/workbook.xml.rels
f
.
addRels
(
"xl/_rels/workbook.xml.rels"
,
SourceRelationshipSharedStrings
,
"sharedStrings.xml"
,
""
)
}
return
f
.
SharedStrings
...
...
xmlSharedStrings.go
浏览文件 @
5c99300e
...
...
@@ -66,7 +66,7 @@ type xlsxR struct {
// xlsxT directly maps the t element in the run properties.
type
xlsxT
struct
{
XMLName
xml
.
Name
`xml:"t"`
Space
string
`xml:"xml:
space,attr,omitempty"`
Space
xml
.
Attr
`xml:"
space,attr,omitempty"`
Val
string
`xml:",innerxml"`
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录