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

     1  package record
     2  
     3  import (
     4  	"bytes"
     5  	"github.com/shakinm/xlsReader/xls/structure"
     6  	"strings"
     7  )
     8  
     9  //This record stores the sheet name, sheet type, and stream position
    10  var BoundSheetRecord = [2]byte{0x85, 0x00} //(85h)
    11  
    12  /*
    13  Offset		 Field Name		 Size		 Contents
    14  -------------------------------------------------
    15  4			lbPlyPos		4			Stream position of the start of the BOF record for the sheet
    16  8			grbit			2			Option flags
    17  10			cch				1			Sheet name ( grbit / rgb fields of Unicode String)
    18  11			rgch			var			Sheet name ( grbit / rgb fields of Unicode String)
    19  */
    20  
    21  /*
    22  The grbit structure contains the following options:
    23  
    24  Bits	Mask	Option Name		Contents
    25  ----------------------------------------
    26  1–0 	0003h 	hsState 		Hidden state:
    27  									00h = visible
    28  									01h = hidden
    29  									02h = very hidden (see text)
    30  7–2 	00FCh 						(Reserved)
    31  15–8	FF00h 	dt				Sheet type:
    32  									00h = worksheet or dialog sheet
    33  									01h = Excel 4.0 macro sheet
    34  									02h = chart
    35  									06h = Visual Basic module
    36  */
    37  
    38  type BoundSheet struct {
    39  	LbPlyPos [4]byte
    40  	Grbit    [2]byte
    41  	Cch      [1]byte
    42  	Rgch     []byte
    43  	stFormat structure.XLUnicodeRichExtendedString
    44  	vers     []byte
    45  
    46  }
    47  
    48  func (r *BoundSheet) Read(stream []byte, vers []byte) {
    49  
    50  	r.vers = vers
    51  
    52  	copy(r.LbPlyPos[:], stream[0:4])
    53  	copy(r.Grbit[:], stream[4:6])
    54  	copy(r.Cch[:], stream[6:7])
    55  
    56  	if bytes.Compare(vers, FlagBIFF8) == 0 {
    57  
    58  		fixedStream:=[]byte{r.Cch[0],0x00}
    59  		fixedStream = append(fixedStream, stream[7:]...)
    60  		_ = r.stFormat.Read(fixedStream)
    61  
    62  	} else {
    63  		r.Rgch = make([]byte, int(r.Cch[0]))
    64  		copy(r.Rgch[:], stream[7:])
    65  	}
    66  }
    67  func (r *BoundSheet) GetName() string {
    68  	if bytes.Compare(r.vers, FlagBIFF8) == 0 {
    69  		return r.stFormat.String()
    70  	}
    71  	strLen := int(r.Cch[0])
    72  	return strings.TrimSpace(string(decodeWindows1251(bytes.Trim(r.Rgch[:int(strLen)], "\x00"))))
    73  }