1
0
mirror of https://github.com/pbnjay/grate.git synced 2024-12-12 13:35:18 +02:00

bugfix and quiet warnings

This commit is contained in:
Jeremy Jay 2021-02-22 01:07:09 -05:00
parent 35d03d67eb
commit 8439b8d161
3 changed files with 55 additions and 87 deletions

View File

@ -125,7 +125,7 @@ func (d *Document) load(rx io.ReadSeeker) error {
if h.MajorVersion != 3 && h.MajorVersion != 4 {
return errors.New("ole2: unknown major version")
}
if h.MinorVersion != 0x3E {
if h.MinorVersion != 0x3B && h.MinorVersion != 0x3E {
log.Printf("WARNING MinorVersion = 0x%02x NOT 0x3E", h.MinorVersion)
//return errors.New("ole2: unknown minor version")
}

View File

@ -221,7 +221,7 @@ func (b *WorkBook) parseSheet(s *boundSheet, ss int) (*commonxl.Sheet, error) {
if ixfe < len(b.xfs) {
fno = b.xfs[ixfe]
}
if fdata[6] == 0xFF && r.Data[7] == 0xFF {
if fdata[6] == 0xFF && fdata[7] == 0xFF {
switch fdata[0] {
case 0:
// string in next record
@ -244,10 +244,10 @@ func (b *WorkBook) parseSheet(s *boundSheet, ss int) (*commonxl.Sheet, error) {
case 3:
// blank string
default:
log.Println("unknown formula value type")
log.Printf("unknown formula value type %d", fdata[0])
}
} else {
xnum := binary.LittleEndian.Uint64(r.Data[6:])
xnum := binary.LittleEndian.Uint64(fdata[6:])
value := math.Float64frombits(xnum)
res.Put(int(formulaRow), int(formulaCol), value, fno)
}

View File

@ -1,117 +1,85 @@
package xls
import (
"os"
"strings"
"testing"
)
func TestHeader(t *testing.T) {
wb, err := Open("../testdata/test.xls")
if err != nil {
t.Fatal(err)
}
var testFiles = []string{
"../testdata/test.xls",
"../testdata/test2.xls",
"../testdata/test3.xls",
"../testdata/test4.xls",
"../testdata/basic.xls",
"../testdata/basic2.xls",
}
sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
//log.Println(s)
sheet, err := wb.Get(s)
func TestLoading(t *testing.T) {
for _, fn := range testFiles {
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}
for sheet.Next() {
sheet.Strings()
sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}
err = wb.Close()
if err != nil {
t.Fatal(err)
for sheet.Next() {
sheet.Strings()
}
}
err = wb.Close()
if err != nil {
t.Fatal(err)
}
}
}
func TestHeader2(t *testing.T) {
wb, err := Open("../testdata/test2.xls")
func noTestBasic(t *testing.T) {
trueFile, err := os.ReadFile("../testdata/basic.tsv")
if err != nil {
t.Fatal(err)
t.Skip()
}
lines := strings.Split(string(trueFile), "\n")
sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
//log.Println(s)
sheet, err := wb.Get(s)
for _, fn := range testFiles {
wb, err := Open(fn)
if err != nil {
t.Fatal(err)
}
for sheet.Next() {
sheet.Strings()
}
}
err = wb.Close()
if err != nil {
t.Fatal(err)
}
}
func TestHeader3(t *testing.T) {
wb, err := Open("../testdata/test3.xls")
if err != nil {
t.Fatal(err)
}
sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
//log.Println(s)
sheet, err := wb.Get(s)
sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
sheet, err := wb.Get(s)
if err != nil {
t.Fatal(err)
}
for sheet.Next() {
sheet.Strings()
i := 0
for sheet.Next() {
row := strings.Join(sheet.Strings(), "\t")
if lines[i] != row {
t.Fatalf("line %d mismatch: '%s' <> '%s'", i, row, lines[i])
}
i++
}
}
}
err = wb.Close()
if err != nil {
t.Fatal(err)
}
}
func TestHeader4(t *testing.T) {
wb, err := Open("../testdata/test4.xls")
if err != nil {
t.Fatal(err)
}
sheets, err := wb.List()
if err != nil {
t.Fatal(err)
}
for _, s := range sheets {
//log.Println(s)
sheet, err := wb.Get(s)
err = wb.Close()
if err != nil {
t.Fatal(err)
}
for sheet.Next() {
sheet.Strings()
}
}
err = wb.Close()
if err != nil {
t.Fatal(err)
}
}