From e37e060d6f97274c1e967cea40609623493bce25 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 31 Dec 2021 00:00:01 +0800 Subject: This closes #1107, stream writer will create a time number format for time type cells Unit test coverage improved --- stream.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'stream.go') diff --git a/stream.go b/stream.go index 4bd721e..8df308d 100644 --- a/stream.go +++ b/stream.go @@ -341,7 +341,7 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}, opts ...RowOpt val = v.Value setCellFormula(&c, v.Formula) } - if err = setCellValFunc(&c, val); err != nil { + if err = sw.setCellValFunc(&c, val); err != nil { _, _ = sw.rawData.WriteString(``) return err } @@ -424,7 +424,7 @@ func setCellFormula(c *xlsxC, formula string) { } // setCellValFunc provides a function to set value of a cell. -func setCellValFunc(c *xlsxC, val interface{}) (err error) { +func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) (err error) { switch val := val.(type) { case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: err = setCellIntFunc(c, val) @@ -439,7 +439,12 @@ func setCellValFunc(c *xlsxC, val interface{}) (err error) { case time.Duration: c.T, c.V = setCellDuration(val) case time.Time: - c.T, c.V, _, err = setCellTime(val) + var isNum bool + c.T, c.V, isNum, err = setCellTime(val) + if isNum && c.S == 0 { + style, _ := sw.File.NewStyle(&Style{NumFmt: 22}) + c.S = style + } case bool: c.T, c.V = setCellBool(val) case nil: -- cgit v1.2.1