From 0701313fa74aa15ee462dc8bb8aacfc9b924e1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 19 Nov 2021 16:13:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9F=BA=E7=A1=80=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- excel/read.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 excel/read.go diff --git a/excel/read.go b/excel/read.go new file mode 100644 index 0000000..f8d0bda --- /dev/null +++ b/excel/read.go @@ -0,0 +1,65 @@ +// Package excel... +// +// Description : excel... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-11-19 3:59 下午 +package excel + +import ( + "github.com/xuri/excelize/v2" +) + +// NewRead 获取读取实例 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:00 下午 2021/11/19 +func NewRead(fullFilePath string, filePassword string) (*Read, error) { + var err error + read := &Read{} + if read.fileHandler, err = excelize.OpenFile(fullFilePath, excelize.Options{Password: filePassword}); nil != err { + return nil, err + } + return read, nil +} + +// Read ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:03 下午 2021/11/19 +type Read struct { + fileHandler *excelize.File +} + +// GetAllSheetList ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:06 下午 2021/11/19 +func (r *Read) GetAllSheetList() []string { + return r.fileHandler.GetSheetList() +} + +// GetAllData 读取全部数据 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:07 下午 2021/11/19 +func (r *Read) GetAllData() (map[string][][]string, error) { + var ( + sheetList []string + result map[string][][]string + err error + ) + sheetList = r.GetAllSheetList() + result = make(map[string][][]string) + for _, sheetName := range sheetList { + if result[sheetName], err = r.fileHandler.GetRows(sheetName); nil != err { + return nil, err + } + } + return result, nil +}