From 79987c0cd7f3711e20df106043c5921ee53e1d47 Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Tue, 21 Feb 2017 16:59:50 +0800 Subject: [PATCH] fix bug --- README.md | 28 +--------------------------- workbook.go | 9 +++++---- xls_test.go | 5 +++-- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b824d68..494424e 100644 --- a/README.md +++ b/README.md @@ -17,31 +17,5 @@ It has just the reading function without the format. * Use **Open** function for open file * Use **OpenReader** function for open xls from a reader -These methods will open a workbook object for reading, like - - func (w *WorkBook) ReadAllCells() (res [][]string) { - for _, sheet := range w.Sheets { - w.PrepareSheet(sheet) - if sheet.MaxRow != 0 { - temp := make([][]string, sheet.MaxRow+1) - for k, row := range sheet.Rows { - data := make([]string, 0) - if len(row.Cols) > 0 { - for _, col := range row.Cols { - if uint16(len(data)) <= col.LastCol() { - data = append(data, make([]string, col.LastCol()-uint16(len(data))+1)...) - } - str := col.String(w) - for i := uint16(0); i < col.LastCol()-col.FirstCol()+1; i++ { - data[col.FirstCol()+i] = str[i] - } - } - temp[k] = data - } - } - res = append(res, temp...) - } - } - return - } +* Follow the example in GODOC diff --git a/workbook.go b/workbook.go index be0d344..2bb0486 100644 --- a/workbook.go +++ b/workbook.go @@ -115,14 +115,15 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int var size uint16 var i = 0 for ; i < int(info.Count); i++ { - if err := binary.Read(buf_item, binary.LittleEndian, &size); err == nil { + var err error + if err = binary.Read(buf_item, binary.LittleEndian, &size); err == nil { var str string str, err = wb.get_string(buf_item, size) wb.sst[i] = wb.sst[i] + str + } - if err == io.EOF { - break - } + if err == io.EOF { + break } } offset = i diff --git a/xls_test.go b/xls_test.go index fd40ad3..1cef2e5 100644 --- a/xls_test.go +++ b/xls_test.go @@ -7,10 +7,10 @@ import ( ) func TestOpen(t *testing.T) { - if xlFile, err := Open("expenses.xls", "utf-8"); err == nil { + if xlFile, err := Open("t1.xls", "utf-8"); err == nil { if sheet1 := xlFile.GetSheet(0); sheet1 != nil { fmt.Println("Total Lines ", sheet1.MaxRow, sheet1.Name) - for i := 0; i <= int(sheet1.MaxRow); i++ { + for i := 265; i <= 267; i++ { fmt.Printf("row %v point %v \n", i, sheet1.Row(i)) if sheet1.Row(i) == nil { continue @@ -18,6 +18,7 @@ func TestOpen(t *testing.T) { row := sheet1.Row(i) for index := row.FirstCol(); index < row.LastCol(); index++ { fmt.Println(index, "==>", row.Col(index), " ") + fmt.Printf("%T\n", row.cols[uint16(index)]) } // col1 := .Cols[0] // col2 := sheet1.Row(uint16(i)].Cols[1]