20
0

add OpenWithCloser function

This commit is contained in:
刘铭 2018-03-22 09:25:17 +08:00
parent e220ff4a46
commit d1d6f84447
2 changed files with 15 additions and 6 deletions

View File

@ -4,22 +4,21 @@
Pure Golang xls library writen by [Rongshu Tech(chinese)](http://www.rongshu.tech). 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. Thanks for contributions from Tamás Gulácsi, sergeilem.
**English User please mailto** [Liu Ming](mailto:liuming@rongshu.tech) **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. 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 # Basic Usage
* Use **Open** function for open file * 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 * Follow the example in GODOC

10
xls.go
View File

@ -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 //Open xls file from reader
func OpenReader(reader io.ReadSeeker, charset string) (wb *WorkBook, err error) { func OpenReader(reader io.ReadSeeker, charset string) (wb *WorkBook, err error) {
var ole *ole2.Ole var ole *ole2.Ole