diff options
author | xuri <xuri.me@gmail.com> | 2022-05-02 12:30:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 12:30:18 +0800 |
commit | eed431e0fc2f61b13e7745857a41cb47d9f7f810 (patch) | |
tree | 8244e1b4749d177313e51a3d73686d16c0176451 /cell.go | |
parent | 773d4afa32a55349a7b178c4c76d182f9ed0221f (diff) |
This closes #1219, fixes cell value reading issue, improves performance, and 1904 date system support
- Fix incorrect cell data types casting results when number formatting
- Support set cell value on 1904 date system enabled, ref #1212
- Improve performance for set sheet row and the merging cells, fix performance impact when resolving #1129
Diffstat (limited to 'cell.go')
-rw-r--r-- | cell.go | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -211,9 +211,12 @@ func (f *File) setCellTimeFunc(sheet, axis string, value time.Time) error { ws.Lock() cellData.S = f.prepareCellStyle(ws, col, row, cellData.S) ws.Unlock() - + date1904, wb := false, f.workbookReader() + if wb != nil && wb.WorkbookPr != nil { + date1904 = wb.WorkbookPr.Date1904 + } var isNum bool - cellData.T, cellData.V, isNum, err = setCellTime(value) + cellData.T, cellData.V, isNum, err = setCellTime(value, date1904) if err != nil { return err } @@ -225,11 +228,11 @@ func (f *File) setCellTimeFunc(sheet, axis string, value time.Time) error { // setCellTime prepares cell type and Excel time by given Go time.Time type // timestamp. -func setCellTime(value time.Time) (t string, b string, isNum bool, err error) { +func setCellTime(value time.Time, date1904 bool) (t string, b string, isNum bool, err error) { var excelTime float64 _, offset := value.In(value.Location()).Zone() value = value.Add(time.Duration(offset) * time.Second) - if excelTime, err = timeToExcelTime(value); err != nil { + if excelTime, err = timeToExcelTime(value, date1904); err != nil { return } isNum = excelTime > 0 @@ -1122,8 +1125,7 @@ func (f *File) formattedValue(s int, v string, raw bool) string { if wb != nil && wb.WorkbookPr != nil { date1904 = wb.WorkbookPr.Date1904 } - ok := builtInNumFmtFunc[numFmtID] - if ok != nil { + if ok := builtInNumFmtFunc[numFmtID]; ok != nil { return ok(v, builtInNumFmt[numFmtID], date1904) } if styleSheet == nil || styleSheet.NumFmts == nil { @@ -1140,15 +1142,18 @@ func (f *File) formattedValue(s int, v string, raw bool) string { // prepareCellStyle provides a function to prepare style index of cell in // worksheet by given column index and style index. func (f *File) prepareCellStyle(ws *xlsxWorksheet, col, row, style int) int { - if ws.Cols != nil && style == 0 { + if style != 0 { + return style + } + if ws.Cols != nil { for _, c := range ws.Cols.Col { if c.Min <= col && col <= c.Max && c.Style != 0 { return c.Style } } } - for rowIdx := range ws.SheetData.Row { - if styleID := ws.SheetData.Row[rowIdx].S; style == 0 && styleID != 0 { + if row <= len(ws.SheetData.Row) { + if styleID := ws.SheetData.Row[row-1].S; styleID != 0 { return styleID } } |