summaryrefslogtreecommitdiff
path: root/stream.go
diff options
context:
space:
mode:
authorcharles.deng <cilendeng@gmail.com>2022-10-10 00:11:18 +0800
committerGitHub <noreply@github.com>2022-10-10 00:11:18 +0800
commit2f5704b114d033e81725f18459f9293a9adfee1e (patch)
tree0390794673f81669ce8a5d20571c2035c4691586 /stream.go
parentb1e776ee33ec78b7f6c2a0de8109009963dea521 (diff)
Stream writer support to set inline rich text cell (#1121)
Co-authored-by: zhengchao.deng <zhengchao.deng@meican.com>
Diffstat (limited to 'stream.go')
-rw-r--r--stream.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/stream.go b/stream.go
index b99730d..66c0fda 100644
--- a/stream.go
+++ b/stream.go
@@ -56,7 +56,14 @@ type StreamWriter struct {
// if err != nil {
// fmt.Println(err)
// }
-// if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data"}},
+// if err := streamWriter.SetRow("A1",
+// []interface{}{
+// excelize.Cell{StyleID: styleID, Value: "Data"},
+// []excelize.RichTextRun{
+// {Text: "Rich ", Font: &excelize.Font{Color: "2354e8"}},
+// {Text: "Text", Font: &excelize.Font{Color: "e83723"}},
+// },
+// },
// excelize.RowOpts{Height: 45, Hidden: false}); err != nil {
// fmt.Println(err)
// }
@@ -433,7 +440,8 @@ func setCellFormula(c *xlsxC, formula string) {
}
// setCellValFunc provides a function to set value of a cell.
-func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) (err error) {
+func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) error {
+ var err error
switch val := val.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
err = setCellIntFunc(c, val)
@@ -462,6 +470,9 @@ func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) (err error) {
c.T, c.V = setCellBool(val)
case nil:
c.T, c.V, c.XMLSpace = setCellStr("")
+ case []RichTextRun:
+ c.T, c.IS = "inlineStr", &xlsxSI{}
+ c.IS.R, err = setRichText(val)
default:
c.T, c.V, c.XMLSpace = setCellStr(fmt.Sprint(val))
}
@@ -519,6 +530,12 @@ func writeCell(buf *bufferedWriter, c xlsxC) {
_ = xml.EscapeText(buf, []byte(c.V))
_, _ = buf.WriteString(`</v>`)
}
+ if c.IS != nil {
+ is, _ := xml.Marshal(c.IS.R)
+ _, _ = buf.WriteString(`<is>`)
+ _, _ = buf.Write(is)
+ _, _ = buf.WriteString(`</is>`)
+ }
_, _ = buf.WriteString(`</c>`)
}