Merge pull request #647 from heiy/master

escape html tag
This commit is contained in:
xuri 2020-06-08 19:02:50 +08:00 committed by GitHub
commit 8ce48b859a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"html"
"reflect"
"strconv"
"strings"
@ -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: textRun.Text}}
run := xlsxR{T: &xlsxT{Val: html.EscapeString(textRun.Text)}}
if strings.ContainsAny(textRun.Text, "\r\n ") {
run.T.Space = xml.Attr{Name: xml.Name{Space: NameSpaceXML, Local: "space"}, Value: "preserve"}
}