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 +}