FIX: issue #47
This commit is contained in:
parent
d1f3d0bd6a
commit
6a6d15a25c
34
workbook.go
34
workbook.go
@ -3,10 +3,10 @@ package xls
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
"io"
|
||||
"os"
|
||||
"unicode/utf16"
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
)
|
||||
|
||||
//xls workbook type
|
||||
@ -86,11 +86,6 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
|
||||
case 0x042: // CODEPAGE
|
||||
binary.Read(buf_item, binary.LittleEndian, &wb.Codepage)
|
||||
case 0x3c: // CONTINUE
|
||||
// step back if previous element not yet completed
|
||||
if wb.continue_utf16 > 0 {
|
||||
offset_pre--
|
||||
}
|
||||
|
||||
if pre.Id == 0xfc {
|
||||
var size uint16
|
||||
var err error
|
||||
@ -102,10 +97,8 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
|
||||
}
|
||||
for err == nil && offset_pre < len(wb.sst) {
|
||||
var str string
|
||||
if size > 0 {
|
||||
str, err = wb.get_string(buf_item, size)
|
||||
wb.sst[offset_pre] = wb.sst[offset_pre] + str
|
||||
}
|
||||
str, err = wb.get_string(buf_item, size)
|
||||
wb.sst[offset_pre] = wb.sst[offset_pre] + str
|
||||
|
||||
if err == io.EOF {
|
||||
break
|
||||
@ -128,7 +121,8 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
|
||||
offset = 0
|
||||
for ; i < int(info.Count); i++ {
|
||||
var err error
|
||||
if err = binary.Read(buf_item, binary.LittleEndian, &size); err == nil {
|
||||
err = binary.Read(buf_item, binary.LittleEndian, &size)
|
||||
if err == nil {
|
||||
var str string
|
||||
str, err = wb.get_string(buf_item, size)
|
||||
wb.sst[i] = wb.sst[i] + str
|
||||
@ -139,7 +133,7 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
|
||||
}
|
||||
}
|
||||
offset = i
|
||||
case 0x85: // bOUNDSHEET
|
||||
case 0x85: // boundsheet
|
||||
var bs = new(boundsheet)
|
||||
binary.Read(buf_item, binary.LittleEndian, bs)
|
||||
// different for BIFF5 and BIFF8
|
||||
@ -169,9 +163,9 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
|
||||
return
|
||||
}
|
||||
func decodeWindows1251(enc []byte) string {
|
||||
dec := charmap.Windows1251.NewDecoder()
|
||||
out, _ := dec.Bytes(enc)
|
||||
return string(out)
|
||||
dec := charmap.Windows1251.NewDecoder()
|
||||
out, _ := dec.Bytes(enc)
|
||||
return string(out)
|
||||
}
|
||||
func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err error) {
|
||||
if w.Is5ver {
|
||||
@ -199,8 +193,6 @@ func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err e
|
||||
if flag&0x1 != 0 {
|
||||
var bts = make([]uint16, size)
|
||||
var i = uint16(0)
|
||||
// we need local err here
|
||||
var err error
|
||||
for ; i < size && err == nil; i++ {
|
||||
err = binary.Read(buf, binary.LittleEndian, &bts[i])
|
||||
}
|
||||
@ -208,15 +200,15 @@ func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err e
|
||||
// when eof found, we dont want to append last element
|
||||
var runes []rune
|
||||
if err == io.EOF {
|
||||
runes = utf16.Decode(bts[:i-1])
|
||||
} else {
|
||||
runes = utf16.Decode(bts[:i])
|
||||
i = i - 1
|
||||
}
|
||||
runes = utf16.Decode(bts[:i])
|
||||
|
||||
res = string(runes)
|
||||
if i < size {
|
||||
w.continue_utf16 = size - i + 1
|
||||
w.continue_utf16 = size - i
|
||||
}
|
||||
|
||||
} else {
|
||||
var bts = make([]byte, size)
|
||||
var n int
|
||||
|
Loading…
Reference in New Issue
Block a user