diff --git a/README.md b/README.md index 29c1607..099dbbb 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,15 @@ Thanks for contributions from Tamás Gulácsi, sergeilem. This is a xls library writen in pure Golang. Almostly it is translated from the libxls library in c. -It has just the reading function without the format. +The master brunch has just the reading function without the format. + +***new_formater** branch is for better format for date and number ,but just under test, you can try it in development environment. If you have some problem about the output format, tell me the problem, I will try to fix it.* # Basic Usage * Use **Open** function for open file -* Use **OpenReader** function for open xls from a reader +* Use **OpenWithCloser** function for open file and use the return value closer for close file +* Use **OpenReader** function for open xls from a reader, you should close related file in your own code * Follow the example in GODOC diff --git a/workbook.go b/workbook.go index b203432..c596e9a 100644 --- a/workbook.go +++ b/workbook.go @@ -101,6 +101,10 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int wb.sst[offset_pre] = wb.sst[offset_pre] + str } + if err == io.EOF { + break + } + offset_pre++ err = binary.Read(buf_item, binary.LittleEndian, &size) } diff --git a/xls.go b/xls.go index b425fc3..7979cb9 100644 --- a/xls.go +++ b/xls.go @@ -16,6 +16,16 @@ func Open(file string, charset string) (*WorkBook, error) { } } +//Open one xls file and return the closer +func OpenWithCloser(file string, charset string) (*WorkBook, io.Closer, error) { + if fi, err := os.Open(file); err == nil { + wb, err := OpenReader(fi, charset) + return wb, fi, err + } else { + return nil, nil, err + } +} + //Open xls file from reader func OpenReader(reader io.ReadSeeker, charset string) (wb *WorkBook, err error) { var ole *ole2.Ole