feature/excel #1

Merged
zhangdeman merged 7 commits from feature/excel into master 2021-11-19 16:45:57 +08:00
Showing only changes of commit 0701313fa7 - Show all commits

65
excel/read.go Normal file
View File

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