Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cfb/cfb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cfb
import (
"bytes"
"encoding/binary"
"github.com/shakinm/xlsReader/helpers"
"io"
"os"
"path/filepath"

"github.com/shakinm/xlsReader/helpers"
)

// Cfb - Compound File Binary
Expand Down Expand Up @@ -227,14 +228,16 @@ func (cfb *Cfb) getFatSectors() (err error) { // nolint: gocyclo
}
func (cfb *Cfb) getDataFromMiniFat(miniFatSectorLocation uint32, offset uint32) (data []byte, err error) {

sPoint := cfb.sectorOffset(miniFatSectorLocation)
point := sPoint + cfb.calculateMiniFatOffset(offset)
point := cfb.calculateMiniFatOffset(offset)

containerStreamBytes, _ := cfb.getDataFromFatChain(miniFatSectorLocation)
containerStream := bytes.NewReader(containerStreamBytes)

for {

sector := NewMiniFatSector(&cfb.header)

err = cfb.getData(point, &sector.Data)
_, err := containerStream.ReadAt(sector.Data, int64(point))

if err != nil {
return data, err
Expand All @@ -248,7 +251,7 @@ func (cfb *Cfb) getDataFromMiniFat(miniFatSectorLocation uint32, offset uint32)

offset = cfb.miniFatPositions[offset]

point = sPoint + cfb.calculateMiniFatOffset(offset)
point = cfb.calculateMiniFatOffset(offset)

}

Expand Down
17 changes: 15 additions & 2 deletions xls/record/sst.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ type SST struct {
Rgb []structure.XLUnicodeRichExtendedString
chLen int
ByteLen int

// These are needed to properly handle CONTINUE records.
// CONTINUE record contains grbit in the first byte unless it's a formatting run
// so we need to know whether all the string bytes have been consumed.
// OpenOffice.org - Microsoft Excel File Format - section 5.21
RgbDone bool
Grbit byte
}

func (s *SST) RgbAppend(bts []byte) (err error) {
Expand Down Expand Up @@ -80,9 +87,15 @@ func (s *SST) Read(readType string, grbit byte, prevLen int32) () {

readType = ""

if cch >= (len(s.RgbSrc)-3)/(1+int(grbit&1)) || s.ByteLen > 0 {
s.Grbit = grbit

headLen := 3
headLen += int(grbit>>2&1) * 4
headLen += int(grbit>>3&1) * 2

if cch >= (len(s.RgbSrc)-headLen)/(1+int(grbit&1)) || s.ByteLen > 0 {

addBytesLen := (len(s.RgbSrc) - 3) - s.ByteLen
addBytesLen := (len(s.RgbSrc) - headLen) - s.ByteLen

if cch-s.chLen > addBytesLen/(1+int(grbit&1)) {
s.chLen = s.chLen + addBytesLen/(1+int(grbit&1))
Expand Down
3 changes: 2 additions & 1 deletion xls/workbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ Next:
if SSTContinue {
readType = "continue"

if len(wb.sst.RgbSrc) == 0 {
if len(wb.sst.RgbSrc) == 0 || wb.sst.RgbDone {
grbitOffset = 0
} else {
grbitOffset = 1
}

grbit = stream[sPoint]
grbit |= wb.sst.Grbit & 0b1100

wb.sst.RgbSrc = append(wb.sst.RgbSrc, stream[sPoint+grbitOffset:sPoint+recordDataLength]...)
wb.sst.Read(readType, grbit, prevLen)
Expand Down