summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/cell.go b/cell.go
index 126b1ff..3a3474f 100644
--- a/cell.go
+++ b/cell.go
@@ -91,9 +91,9 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
case uint64:
f.SetCellInt(sheet, axis, int(v))
case float32:
- f.SetCellDefault(sheet, axis, strconv.FormatFloat(float64(v), 'f', -1, 32))
+ f.SetCellFloat(sheet, axis, float64(v), -1, 32)
case float64:
- f.SetCellDefault(sheet, axis, strconv.FormatFloat(v, 'f', -1, 64))
+ f.SetCellFloat(sheet, axis, v, -1, 64)
case string:
f.SetCellStr(sheet, axis, v)
case []byte:
@@ -142,6 +142,21 @@ func (f *File) SetCellBool(sheet, axis string, value bool) {
}
}
+// SetCellFloat sets a floating point value into a cell. The prec parameter
+// specifies how many places after the decimal will be shown while -1
+// is a special value that will use as many decimal places as necessary to
+// represent the number. bitSize is 32 or 64 depending on if a float32 or float64
+// was originally used for the value
+// var x float32 = 1.325
+// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
+func (f *File) SetCellFloat(sheet, axis string, value float64, prec, bitSize int) {
+ xlsx := f.workSheetReader(sheet)
+ cellData, col, _ := f.prepareCell(xlsx, sheet, axis)
+ cellData.S = f.prepareCellStyle(xlsx, col, cellData.S)
+ cellData.T = ""
+ cellData.V = strconv.FormatFloat(value, 'f', prec, 64)
+}
+
// SetCellStr provides a function to set string type value of a cell. Total
// number of characters that a cell can contain 32767 characters.
func (f *File) SetCellStr(sheet, axis, value string) {