summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-09-26 00:07:40 +0800
committerxuri <xuri.me@gmail.com>2021-09-26 00:07:40 +0800
commit490f3063c2cb35a94d64f6a6859cce7b9dee276d (patch)
tree67b21487eabea5bff15fd1bcdc7db8e60996b452 /cell.go
parentc05b9fe8a6e6cadad0de7821bd33fa5cc283c8e4 (diff)
This closes #1026, time parse accuracy issue and typo fixed
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/cell.go b/cell.go
index 902f5b7..b95db9c 100644
--- a/cell.go
+++ b/cell.go
@@ -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