Skip to content

Commit d83ae68

Browse files
author
mengzhongyuan
committed
This close #2151, streaming writer can set cell default value
Change-Id: If019aea806b9527937a9fe8d90050d2ef3d783b0 Signed-off-by: mengzhongyuan <mengzhongyuan@bytedance.com>
1 parent 8ebe713 commit d83ae68

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

cell.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ func (c *xlsxC) getCellBool(f *File, raw bool) (string, error) {
571571
return f.formattedValue(c, raw, CellTypeBool)
572572
}
573573

574+
// SetCellDefaultValue is a type for setCellDefault function, pass this type data, setCellDefault will be used to
575+
// perform the write operation.
576+
type SetCellDefaultValue string
577+
574578
// setCellDefault prepares cell type and string type cell value by a given
575579
// string.
576580
func (c *xlsxC) setCellDefault(value string) {
@@ -580,7 +584,8 @@ func (c *xlsxC) setCellDefault(value string) {
580584
c.IS.T.Val = value
581585
return
582586
}
583-
c.T, c.V, c.IS = value, value, nil
587+
588+
c.T, c.V, c.IS = "", "", nil // I modify this to set c.T = "" explicitly to avoid misunderstanding of c.Type can be value
584589
return
585590
}
586591
c.T, c.V = "", value

stream.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@ func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) error {
568568
case []RichTextRun:
569569
c.T, c.IS = "inlineStr", &xlsxSI{}
570570
c.IS.R, err = setRichText(val)
571+
case SetCellDefaultValue:
572+
c.setCellDefault(string(val))
571573
default:
572574
c.setCellValue(fmt.Sprint(val))
573575
}

stream_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ func TestStreamSetCellValFunc(t *testing.T) {
408408
true,
409409
nil,
410410
complex64(5 + 10i),
411+
SetCellDefaultValue("100.1588"),
412+
SetCellDefaultValue(" Hello"),
411413
} {
412414
assert.NoError(t, sw.setCellValFunc(c, val))
413415
}

0 commit comments

Comments
 (0)