增加基础的数据读取
This commit is contained in:
parent
62cdd3570a
commit
0701313fa7
65
excel/read.go
Normal file
65
excel/read.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user