diff --git a/xls/cfb/cfb.go b/xls/cfb/cfb.go index cc33eb6..2692ba4 100644 --- a/xls/cfb/cfb.go +++ b/xls/cfb/cfb.go @@ -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") } diff --git a/xls/sheets.go b/xls/sheets.go index 3be1be4..7c58fec 100644 --- a/xls/sheets.go +++ b/xls/sheets.go @@ -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) } diff --git a/xls/simple_test.go b/xls/simple_test.go index 64bccb0..6b0035b 100644 --- a/xls/simple_test.go +++ b/xls/simple_test.go @@ -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) } }