github.com/shakinm/xlsReader@v0.9.12/xls/record/rk.go (about)

     1  package record
     2  
     3  import (
     4  	"github.com/shakinm/xlsReader/helpers"
     5  	"github.com/shakinm/xlsReader/xls/structure"
     6  	"reflect"
     7  )
     8  
     9  // RK: Cell Value, RK Number
    10  
    11  var RkRecord = []byte{0x7E, 0x02} //(7Eh)
    12  /*
    13  Excel uses an internal number type, called an RK number, to save memory and disk
    14  space.
    15  
    16  Record Data
    17  Offset		Name		Size		Contents
    18  --------------------------------------------
    19  4			rw			2			Row
    20  6			col			2			Column
    21  8			ixfe		2			Index to the XF record
    22  10			rk			4			RK number (see the following description)
    23  
    24  An RK number is either a 30-bit integer or the most significant 30 bits of an IEEE
    25  number. The two LSBs of the 32-bit rk field are always reserved for RK type
    26  encoding; this is why the RK numbers are 30 bits, not the full 32.
    27  
    28  */
    29  
    30  type Rk struct {
    31  	rw   [2]byte
    32  	col  [2]byte
    33  	ixfe [2]byte
    34  	rk   structure.RKNum
    35  }
    36  
    37  func (r *Rk) GetRow() [2]byte {
    38  	return r.rw
    39  }
    40  
    41  func (r *Rk) GetCol() [2]byte {
    42  	return r.col
    43  }
    44  
    45  func (r *Rk) GetFloat64() float64 {
    46  	return r.rk.GetFloat()
    47  }
    48  
    49  func (r *Rk) GetInt64() int64 {
    50  	return r.rk.GetInt64()
    51  }
    52  
    53  func (r *Rk) GetType() string {
    54  	return reflect.TypeOf(r).String()
    55  }
    56  
    57  func (r *Rk) GetString() (s string) {
    58  	return r.rk.GetString()
    59  }
    60  
    61  func (r *Rk) GetXFIndex() int {
    62  	return int(helpers.BytesToUint16(r.ixfe[:]))
    63  }
    64  
    65  func (r *Rk) Read(stream []byte) {
    66  	copy(r.rw[:], stream[:2])
    67  	copy(r.col[:], stream[2:4])
    68  	copy(r.ixfe[:], stream[4:6])
    69  	copy(r.rk[:], stream[6:10])
    70  }
    71  
    72  func (r *Rk) Get() *Rk {
    73  	return r
    74  }