github.com/shakinm/xlsReader@v0.9.12/xls/record/boolerr.go (about) 1 package record 2 3 import ( 4 "github.com/shakinm/xlsReader/helpers" 5 "reflect" 6 "strconv" 7 ) 8 9 //BOOLERR: Cell Value, Boolean or Error 10 11 var BoolErrRecord = []byte{0x05, 0x02} // (205h) 12 13 /* 14 A BOOLERR record describes a cell that contains a constant Boolean or error value. 15 The rw field contains the 0-based row number. The col field contains the 0-based 16 column number. 17 18 Record Data 19 Offset Field Name Size Contents 20 ------------------------------------------------ 21 4 rw 2 Row 22 6 col 2 Col 23 8 ixfe 2 Index to the XF record 24 10 bBoolErr 1 Boolean value or error value 25 11 fError 1 Boolean/error flag 26 27 The bBoolErr field contains the Boolean or error value, as determined by the 28 fError field. If the fError field contains a 0 (zero), the bBoolErr field contains a 29 Boolean value; if the fError field contains a 1, the bBoolErr field contains an error 30 value. 31 Boolean values are 1 for true and 0 for false. 32 Error values are listed in the following table. 33 34 Error value Value (hex) Value (dec.) 35 -------------------------------------------- 36 #NULL! 00h 0 37 #DIV/0! 07h 7 38 #VALUE! 0Fh 15 39 #REF! 17h 23 40 #NAME? 1Dh 29 41 #NUM! 24h 36 42 #N/A 2Ah 42 43 */ 44 45 type BoolErr struct { 46 rw [2]byte 47 col [2]byte 48 ixfe [2]byte 49 bBoolErr [1]byte 50 fError [1]byte 51 } 52 53 func (r *BoolErr) GetRow() [2]byte { 54 return r.rw 55 } 56 57 func (r *BoolErr) GetCol() [2]byte { 58 return r.col 59 } 60 61 func (r *BoolErr) GetFloat() float64 { 62 63 return float64(r.GetInt64()) 64 } 65 66 func (r *BoolErr) GetString() string { 67 if int(r.fError[0]) == 1 { 68 switch r.GetInt64() { 69 case 0: 70 return "#NULL!" 71 case 7: 72 return "#DIV/0!" 73 case 15: 74 return "#VALUE!" 75 case 23: 76 return "#REF!" 77 case 29: 78 return "#NAME?" 79 case 36: 80 return "#NUM!!" 81 case 42: 82 return "#N/A" 83 } 84 } else { 85 if r.GetInt64() == 1 { 86 return "TRUE" 87 } else { 88 return "FALSE" 89 } 90 } 91 return strconv.FormatInt(r.GetInt64(), 10) 92 } 93 94 func (r *BoolErr) GetFloat64() (fl float64) { 95 return r.GetFloat() 96 } 97 func (r *BoolErr) GetInt64() int64 { 98 return int64(r.bBoolErr[0]) 99 } 100 101 func (r *BoolErr) GetType() string { 102 return reflect.TypeOf(r).String() 103 } 104 105 func (r *BoolErr) GetXFIndex() int { 106 return int(helpers.BytesToUint16(r.ixfe[:])) 107 } 108 109 func (r *BoolErr) Read(stream []byte) { 110 copy(r.rw[:], stream[:2]) 111 copy(r.col[:], stream[2:4]) 112 copy(r.ixfe[:], stream[4:6]) 113 copy(r.bBoolErr[:], stream[6:7]) 114 copy(r.fError[:], stream[7:8]) 115 }