Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Excelize
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Globars Forks
Excelize
Commits
f7bd0729
Unverified
Commit
f7bd0729
authored
Jul 01, 2020
by
xuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve #32, fix missing leading/leading spaces when working with SST
parent
1cbb05d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
17 deletions
+21
-17
cell.go
cell.go
+13
-12
rows.go
rows.go
+2
-2
xmlSharedStrings.go
xmlSharedStrings.go
+6
-3
No files found.
cell.go
View file @
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
View file @
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
View file @
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment