浏览代码

Merge pull request #647 from heiy/master

escape html tag
xuri 5 年之前
父节点
当前提交
8ce48b859a
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      cell.go

+ 2 - 1
cell.go

@@ -13,6 +13,7 @@ import (
 	"encoding/xml"
 	"encoding/xml"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
+	"html"
 	"reflect"
 	"reflect"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -620,7 +621,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
 	sst := f.sharedStringsReader()
 	sst := f.sharedStringsReader()
 	textRuns := []xlsxR{}
 	textRuns := []xlsxR{}
 	for _, textRun := range runs {
 	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 ") {
 		if strings.ContainsAny(textRun.Text, "\r\n ") {
 			run.T.Space = xml.Attr{Name: xml.Name{Space: NameSpaceXML, Local: "space"}, Value: "preserve"}
 			run.T.Space = xml.Attr{Name: xml.Name{Space: NameSpaceXML, Local: "space"}, Value: "preserve"}
 		}
 		}