Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
f7bd0729
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,发现更多精彩内容 >>
已验证
提交
f7bd0729
编写于
7月 01, 2020
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Resolve #32, fix missing leading/leading spaces when working with SST
上级
1cbb05d4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
17 deletion
+21
-17
cell.go
cell.go
+13
-12
rows.go
rows.go
+2
-2
xmlSharedStrings.go
xmlSharedStrings.go
+6
-3
未找到文件。
cell.go
浏览文件 @
f7bd0729
...
...
@@ -15,7 +15,6 @@ import (
"encoding/xml"
"errors"
"fmt"
"html"
"reflect"
"strconv"
"strings"
...
...
@@ -274,23 +273,16 @@ 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
=
f
.
setCellString
(
value
)
cellData
.
T
,
cellData
.
V
=
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
)
{
func
(
f
*
File
)
setCellString
(
value
string
)
(
t
string
,
v
string
)
{
if
len
(
value
)
>
TotalCellChars
{
value
=
value
[
0
:
TotalCellChars
]
}
// 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
...
...
@@ -304,7 +296,16 @@ func (f *File) setSharedString(val string) int {
}
sst
.
Count
++
sst
.
UniqueCount
++
sst
.
SI
=
append
(
sst
.
SI
,
xlsxSI
{
T
:
val
})
t
:=
xlsxT
{
Val
:
val
}
// Leading and ending space(s) character detection.
if
len
(
val
)
>
0
&&
(
val
[
0
]
==
32
||
val
[
len
(
val
)
-
1
]
==
32
)
{
ns
:=
xml
.
Attr
{
Name
:
xml
.
Name
{
Space
:
NameSpaceXML
,
Local
:
"space"
},
Value
:
"preserve"
,
}
t
.
Space
=
ns
}
sst
.
SI
=
append
(
sst
.
SI
,
xlsxSI
{
T
:
&
t
})
f
.
sharedStringsMap
[
val
]
=
sst
.
UniqueCount
-
1
return
sst
.
UniqueCount
-
1
}
...
...
@@ -620,7 +621,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
sst
:=
f
.
sharedStringsReader
()
textRuns
:=
[]
xlsxR
{}
for
_
,
textRun
:=
range
runs
{
run
:=
xlsxR
{
T
:
&
xlsxT
{
Val
:
html
.
EscapeString
(
textRun
.
Text
)
}}
run
:=
xlsxR
{
T
:
&
xlsxT
{
Val
:
textRun
.
Text
}}
if
strings
.
ContainsAny
(
textRun
.
Text
,
"
\r\n
"
)
{
run
.
T
.
Space
=
xml
.
Attr
{
Name
:
xml
.
Name
{
Space
:
NameSpaceXML
,
Local
:
"space"
},
Value
:
"preserve"
}
}
...
...
rows.go
浏览文件 @
f7bd0729
...
...
@@ -292,8 +292,8 @@ func (f *File) sharedStringsReader() *xlsxSST {
}
f
.
SharedStrings
=
&
sharedStrings
for
i
:=
range
sharedStrings
.
SI
{
if
sharedStrings
.
SI
[
i
]
.
T
!=
""
{
f
.
sharedStringsMap
[
sharedStrings
.
SI
[
i
]
.
T
]
=
i
if
sharedStrings
.
SI
[
i
]
.
T
!=
nil
{
f
.
sharedStringsMap
[
sharedStrings
.
SI
[
i
]
.
T
.
Val
]
=
i
}
}
f
.
addContentTypePart
(
0
,
"sharedStrings"
)
...
...
xmlSharedStrings.go
浏览文件 @
f7bd0729
...
...
@@ -38,7 +38,7 @@ type xlsxSST struct {
// level - then the string item shall consist of multiple rich text runs which
// collectively are used to express the string.
type
xlsxSI
struct
{
T
string
`xml:"t,omitempty"`
T
*
xlsxT
`xml:"t,omitempty"`
R
[]
xlsxR
`xml:"r"`
}
...
...
@@ -53,7 +53,10 @@ func (x xlsxSI) String() string {
}
return
rows
.
String
()
}
return
x
.
T
if
x
.
T
!=
nil
{
return
x
.
T
.
Val
}
return
""
}
// xlsxR represents a run of rich text. A rich text run is a region of text
...
...
@@ -69,7 +72,7 @@ type xlsxR struct {
type
xlsxT
struct
{
XMLName
xml
.
Name
`xml:"t"`
Space
xml
.
Attr
`xml:"space,attr,omitempty"`
Val
string
`xml:",
innerxml
"`
Val
string
`xml:",
chardata
"`
}
// xlsxRPr (Run Properties) specifies a set of run properties which shall be
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录