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 { if h.MajorVersion != 3 && h.MajorVersion != 4 {
return errors.New("ole2: unknown major version") 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) log.Printf("WARNING MinorVersion = 0x%02x NOT 0x3E", h.MinorVersion)
//return errors.New("ole2: unknown minor version") //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) { if ixfe < len(b.xfs) {
fno = b.xfs[ixfe] fno = b.xfs[ixfe]
} }
if fdata[6] == 0xFF && r.Data[7] == 0xFF { if fdata[6] == 0xFF && fdata[7] == 0xFF {
switch fdata[0] { switch fdata[0] {
case 0: case 0:
// string in next record // string in next record
@ -244,10 +244,10 @@ func (b *WorkBook) parseSheet(s *boundSheet, ss int) (*commonxl.Sheet, error) {
case 3: case 3:
// blank string // blank string
default: default:
log.Println("unknown formula value type") log.Printf("unknown formula value type %d", fdata[0])
} }
} else { } else {
xnum := binary.LittleEndian.Uint64(r.Data[6:]) xnum := binary.LittleEndian.Uint64(fdata[6:])
value := math.Float64frombits(xnum) value := math.Float64frombits(xnum)
res.Put(int(formulaRow), int(formulaCol), value, fno) res.Put(int(formulaRow), int(formulaCol), value, fno)
} }

View File

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