github.com/shakinm/xlsReader@v0.9.12/xls/record/formula.go (about) 1 package record 2 3 import "github.com/shakinm/xlsReader/helpers" 4 5 //FORMULA: Cell Formula 6 7 var FormulaRecord = []byte{0x06, 0x00} // (6h) 8 9 /* 10 A FORMULA record describes a cell that contains a formula. 11 12 Record Data 13 Offset Field Name Size Contents 14 ------------------------------------------------ 15 4 rw 2 Rw 16 6 col 2 Col 17 8 ixfe 2 Index to XF record 18 10 num 8 Current value of the formula 19 18 grbit 2 Option flags 20 20 chn 4 21 24 cce 2 Length of the parsed expression 22 26 rgce var Parsed expression 23 24 The chn field should be ignored when you read the BIFF file. If you write a BIFF file, 25 the chn field must be 00000000h. 26 The grbit field contains the following option flags: 27 28 Bits Mask FlagName Contents 29 ---------------------------------------- 30 0 0001h fAlwaysCalc Always calculate the formula. 31 1 0002h fCalcOnLoad Calculate the formula when the file is opened. 32 2 0004h (Reserved) 33 3 0008h fShrFmla =1 if the formula is part of shared formula group. 34 15–4 FFF0h (Reserved) 35 36 The rw field contains the 0-based row number. The col field contains the 0-based 37 column number. 38 If the formula evaluates to a number, the num field contains the current calculated 39 value of the formula in 8-byte IEEE format. If the formula evaluates to a string, a 40 Boolean value, or an error value, the most significant 2 bytes of the num field are 41 FFFFh . 42 A Boolean value is stored in the num field, as shown in the following table. For more 43 information about Boolean values, see ― "BOOLERR". 44 45 Offset Field Name Size Contents 46 ------------------------------------------------ 47 0 otBool 1 =1 always 48 1 (Reserved) 1 Reserved; must be 0 (zero) 49 2 f 1 Boolean value 50 3 (Reserved) 3 Reserved; must be 0 (zero) 51 6 fExprO 2 =FFFFh 52 53 An error value is stored in the num field, as shown in the following table. For more 54 information about error values, see "BOOLERR" 55 56 Offset Field Name Size Contents 57 ------------------------------------------------ 58 0 otErr 1 =2 always 59 1 (Reserved) 1 Reserved; must be 0 (zero) 60 2 err 1 Error value 61 3 (Reserved) 3 Reserved; must be 0 (zero) 62 6 fExprO 2 =FFFFh 63 64 If the formula evaluates to a string, the num field has the structure shown in the 65 following table. 66 67 Offset Field Name Size Contents 68 ------------------------------------------------ 69 0 otString 1 =0 always 70 1 (Reserved) 5 Reserved; must be 0 (zero) 71 6 fExprO 2 =FFFFh 72 73 The string value is not stored in the num field; instead, it is stored in a STRING 74 record that immediately follows the FORMULA record. 75 The cce field contains the length of the formula. The rgce field contains the 76 formula in its parsed format. 77 78 */ 79 80 type Formula struct { 81 rw [2]byte 82 col [2]byte 83 ixfe [2]byte 84 num [8]byte 85 grbit [2]byte 86 chn [4]byte 87 cce [2]byte 88 rgce []byte 89 } 90 91 func (r *Formula) GetXFIndex() int { 92 return int(helpers.BytesToUint16(r.ixfe[:])) 93 } 94 95 func (r *Formula) Read(stream []byte) { 96 copy(r.rw[:], stream[:2]) 97 copy(r.col[:], stream[2:4]) 98 copy(r.ixfe[:], stream[4:6]) 99 copy(r.num[:], stream[6:14]) 100 copy(r.grbit[:], stream[14:16]) 101 copy(r.chn[:], stream[16:20]) 102 copy(r.cce[:], stream[20:22]) 103 copy(r.rgce[:], stream[20:]) 104 }