From d1d6f84447510f31419fb325a9f96b657b68f0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=93=AD?= Date: Thu, 22 Mar 2018 09:25:17 +0800 Subject: [PATCH] add OpenWithCloser function --- README.md | 11 +++++------ xls.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a23018c..099dbbb 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,21 @@ Pure Golang xls library writen by [Rongshu Tech(chinese)](http://www.rongshu.tech). - -#new_formaater# branch is under test, if you have the problem about the output format, try it and tell me the problem, I will try to fix it. - - Thanks for contributions from Tamás Gulácsi, sergeilem. **English User please mailto** [Liu Ming](mailto:liuming@rongshu.tech) 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/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