summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--calc.go2
-rw-r--r--cell.go22
-rw-r--r--cell_test.go7
-rw-r--r--rows.go7
4 files changed, 24 insertions, 14 deletions
diff --git a/calc.go b/calc.go
index 266491f..4303b43 100644
--- a/calc.go
+++ b/calc.go
@@ -103,7 +103,7 @@ var (
"june": 6,
"july": 7,
"august": 8,
- "septemper": 9,
+ "september": 9,
"october": 10,
"november": 11,
"december": 12,
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
diff --git a/cell_test.go b/cell_test.go
index 35eaa96..126e561 100644
--- a/cell_test.go
+++ b/cell_test.go
@@ -243,6 +243,13 @@ func TestGetCellValue(t *testing.T) {
{"", "", "", "", "", "", "", "H6"},
}, rows)
assert.NoError(t, err)
+
+ f.Sheet.Delete("xl/worksheets/sheet1.xml")
+ f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(fmt.Sprintf(sheetData, `<row r="1"><c r="A1"><v>2422.3000000000002</v></c><c r="B1"><v>2422.3000000000002</v></c><c r="C1"><v>12.4</v></c><c r="D1"><v>964</v></c><c r="E1"><v>1101.5999999999999</v></c><c r="F1"><v>275.39999999999998</v></c><c r="G1"><v>68.900000000000006</v></c><c r="H1"><v>44385.208333333336</v></c><c r="I1"><v>5.0999999999999996</v></c><c r="J1"><v>5.1100000000000003</v></c><c r="K1"><v>5.0999999999999996</v></c><c r="L1"><v>5.1109999999999998</v></c><c r="M1"><v>5.1111000000000004</v></c><c r="N1"><v>2422.012345678</v></c><c r="O1"><v>2422.0123456789</v></c><c r="P1"><v>12.012345678901</v></c><c r="Q1"><v>964</v></c><c r="R1"><v>1101.5999999999999</v></c><c r="S1"><v>275.39999999999998</v></c><c r="T1"><v>68.900000000000006</v></c></row>`)))
+ f.checked = nil
+ rows, err = f.GetRows("Sheet1")
+ assert.Equal(t, [][]string{{"2422.3", "2422.3", "12.4", "964", "1101.6", "275.4", "68.9", "44385.20833333333", "5.1", "5.11", "5.1", "5.111", "5.1111", "2422.012345678", "2422.0123456789", "12.012345678901", "964", "1101.6", "275.4", "68.9"}}, rows)
+ assert.NoError(t, err)
}
func TestGetCellType(t *testing.T) {
diff --git a/rows.go b/rows.go
index 5c7b22d..3d8c247 100644
--- a/rows.go
+++ b/rows.go
@@ -417,13 +417,6 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST, raw bool) (string, error) {
}
return f.formattedValue(c.S, c.V, raw), nil
default:
- isNum, precision := isNumeric(c.V)
- if isNum && precision > 10 {
- val, _ := roundPrecision(c.V)
- if val != c.V {
- return f.formattedValue(c.S, val, raw), nil
- }
- }
return f.formattedValue(c.S, c.V, raw), nil
}
}