Skip to content

Commit 852e7ce

Browse files
Merge pull request #2 from tespkg/fix/2-fix-export-slowness
#2; Improves export performance by avoiding create new style per time…
2 parents d147e85 + 78aa41b commit 852e7ce

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

cell.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (f *File) SetCellValue(sheet, cell string, value interface{}) error {
144144
if err != nil {
145145
return err
146146
}
147-
err = f.setDefaultTimeStyle(sheet, cell, getDurationNumFmt(v))
147+
err = f.setDefaultTimeStyle(sheet, cell, 21)
148148
case time.Time:
149149
err = f.setCellTimeFunc(sheet, cell, v)
150150
case bool:
@@ -256,7 +256,7 @@ func (f *File) setCellTimeFunc(sheet, cell string, value time.Time) error {
256256
return err
257257
}
258258
if isNum {
259-
_ = f.setDefaultTimeStyle(sheet, cell, getTimeNumFmt(value))
259+
_ = f.setDefaultTimeStyle(sheet, cell, 22)
260260
}
261261
return err
262262
}

excelize.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,15 @@ func (f *File) xmlNewDecoder(rdr io.Reader) (ret *xml.Decoder) {
242242
// time.Time type cell value by given worksheet name, cell reference and
243243
// number format code.
244244
func (f *File) setDefaultTimeStyle(sheet, cell string, format int) error {
245-
styleIdx, err := f.GetCellStyle(sheet, cell)
245+
s, err := f.GetCellStyle(sheet, cell)
246246
if err != nil {
247247
return err
248248
}
249-
if styleIdx == 0 {
250-
styleIdx, _ = f.NewStyle(&Style{NumFmt: format})
251-
} else {
252-
style, _ := f.GetStyle(styleIdx)
253-
style.NumFmt = format
254-
styleIdx, _ = f.NewStyle(style)
249+
if s == 0 {
250+
style, _ := f.NewStyle(&Style{NumFmt: format})
251+
err = f.SetCellStyle(sheet, cell, cell, style)
255252
}
256-
return f.SetCellStyle(sheet, cell, cell, styleIdx)
253+
return err
257254
}
258255

259256
// workSheetReader provides a function to get the pointer to the structure

0 commit comments

Comments
 (0)