github.com/shakinm/xlsReader@v0.9.12/xls/record/number.go (about) 1 package record 2 3 import ( 4 "encoding/binary" 5 "github.com/shakinm/xlsReader/helpers" 6 "math" 7 "reflect" 8 9 "strconv" 10 ) 11 12 //NUMBER: Cell Value, Floating-Point Number 13 14 var NumberRecord = []byte{0x03, 0x02} //(203h) 15 /* 16 A NUMBER record describes a cell containing a constant floating-point number. The 17 rw field contains the 0-based row number. The col field contains the 0-based 18 column number. The number is contained in the num field in 8-byte IEEE floating- 19 point format. 20 21 Record Data 22 Offset Name Size Contents 23 -------------------------------------------- 24 4 rw 2 Row 25 6 col 2 Column 26 8 ixfe 2 Index to the XF record 27 10 num 8 Floating-point number value 28 */ 29 30 type Number struct { 31 rw [2]byte 32 col [2]byte 33 ixfe [2]byte 34 num [8]byte 35 } 36 37 func (r *Number) GetRow() [2]byte { 38 return r.rw 39 } 40 41 func (r *Number) GetCol() [2]byte { 42 return r.col 43 } 44 45 func (r *Number) GetFloat() float64 { 46 bits := binary.LittleEndian.Uint64(r.num[:]) 47 float := math.Float64frombits(bits) 48 return float 49 } 50 51 func (r *Number) GetString() string { 52 53 return strconv.FormatFloat(r.GetFloat(), 'f', -1, 64) 54 } 55 56 func (r *Number) GetFloat64() (fl float64) { 57 return r.GetFloat() 58 } 59 func (r *Number) GetInt64() (in int64) { 60 return in 61 } 62 63 func (r *Number) GetType() string { 64 return reflect.TypeOf(r).String() 65 } 66 67 func (r *Number) GetXFIndex() int { 68 return int(helpers.BytesToUint16(r.ixfe[:])) 69 } 70 71 func (r *Number) Read(stream []byte) { 72 copy(r.rw[:], stream[:2]) 73 copy(r.col[:], stream[2:4]) 74 copy(r.ixfe[:], stream[4:6]) 75 copy(r.num[:], stream[6:14]) 76 }