mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-06 12:01:27 +08:00
数据集
This commit is contained in:
@@ -3,6 +3,7 @@ package tool
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"pandax/apps/visual/entity"
|
||||
)
|
||||
|
||||
// 读取数据表
|
||||
@@ -38,3 +39,51 @@ func ReadExcel(filename string) ([]string, []map[string]interface{}) {
|
||||
}
|
||||
return cols, ret
|
||||
}
|
||||
|
||||
func ReadExcelByFilter(filename string, data entity.DataSetDataReq) ([]string, []map[string]interface{}) {
|
||||
dataDs := make([]string, 0)
|
||||
for _, ds := range data.DataDs {
|
||||
dataDs = append(dataDs, ds.Value)
|
||||
}
|
||||
|
||||
ret := make([]map[string]interface{}, 0)
|
||||
f, err := excelize.OpenFile(filename)
|
||||
if err != nil {
|
||||
fmt.Println("读取excel文件出错", err.Error())
|
||||
return nil, ret
|
||||
}
|
||||
sheets := f.GetSheetMap()
|
||||
sheet1 := sheets[1]
|
||||
rows, err := f.GetRows(sheet1)
|
||||
cols := make([]string, 0)
|
||||
colsIndex := make([]int, 0)
|
||||
isHead := true
|
||||
count := 0
|
||||
for _, row := range rows {
|
||||
if data.ShowNumType == "2" {
|
||||
if count == int(data.ShowNum) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if isHead { //取得第一行的所有数据---execel表头
|
||||
if len(row) == 0 {
|
||||
continue
|
||||
}
|
||||
for i, colCell := range row {
|
||||
cols = append(cols, colCell)
|
||||
colsIndex = append(colsIndex, i)
|
||||
}
|
||||
isHead = false
|
||||
} else {
|
||||
theRow := map[string]interface{}{}
|
||||
for j, colCell := range row {
|
||||
k := cols[j]
|
||||
theRow[k] = colCell
|
||||
|
||||
}
|
||||
ret = append(ret, theRow)
|
||||
}
|
||||
count++
|
||||
}
|
||||
return cols, ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user