diff options
author | xuri <xuri.me@gmail.com> | 2021-09-26 00:07:40 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-09-26 00:07:40 +0800 |
commit | 490f3063c2cb35a94d64f6a6859cce7b9dee276d (patch) | |
tree | 67b21487eabea5bff15fd1bcdc7db8e60996b452 /cell.go | |
parent | c05b9fe8a6e6cadad0de7821bd33fa5cc283c8e4 (diff) |
This closes #1026, time parse accuracy issue and typo fixed
Diffstat (limited to 'cell.go')
-rw-r--r-- | cell.go | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -1043,13 +1043,18 @@ func (f *File) getCellStringFunc(sheet, axis string, fn func(x *xlsxWorksheet, c // it is possible to apply a format to the cell value, it will do so, if not // then an error will be returned, along with the raw value of the cell. func (f *File) formattedValue(s int, v string, raw bool) string { + precise := v + isNum, precision := isNumeric(v) + if isNum && precision > 10 { + precise, _ = roundPrecision(v) + } if s == 0 || raw { - return v + return precise } styleSheet := f.stylesReader() if s >= len(styleSheet.CellXfs.Xf) { - return v + return precise } var numFmtID int if styleSheet.CellXfs.Xf[s].NumFmtID != nil { @@ -1061,18 +1066,23 @@ func (f *File) formattedValue(s int, v string, raw bool) string { return ok(v, builtInNumFmt[numFmtID]) } if styleSheet == nil || styleSheet.NumFmts == nil { - return v + return precise } for _, xlsxFmt := range styleSheet.NumFmts.NumFmt { if xlsxFmt.NumFmtID == numFmtID { format := strings.ToLower(xlsxFmt.FormatCode) - if strings.Contains(format, "y") || strings.Contains(format, "m") || strings.Contains(strings.Replace(format, "red", "", -1), "d") || strings.Contains(format, "h") { + if isTimeNumFmt(format) { return parseTime(v, format) } - return v + return precise } } - return v + return precise +} + +// isTimeNumFmt determine if the given number format expression is a time number format. +func isTimeNumFmt(format string) bool { + return strings.Contains(format, "y") || strings.Contains(format, "m") || strings.Contains(strings.Replace(format, "red", "", -1), "d") || strings.Contains(format, "h") } // prepareCellStyle provides a function to prepare style index of cell in |