summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-07-01 22:41:29 +0800
committerxuri <xuri.me@gmail.com>2020-07-01 22:41:29 +0800
commitf7bd0729c65fc82305328f7ac8fbaf329d1075c0 (patch)
treec8eb5e0fbef268d217acbd3e8cfb76c44ac81fee /cell.go
parent1cbb05d4977fc1c03fa37d704118fd9c722e487d (diff)
Resolve #32, fix missing leading/leading spaces when working with SST
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/cell.go b/cell.go
index fa46007..0163c3b 100644
--- a/cell.go
+++ b/cell.go
@@ -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"}
}