完善excel2导出

This commit is contained in:
xiangheng
2024-08-13 01:21:10 +08:00
parent c1b3b91e32
commit 1fc96a59b0
7 changed files with 96 additions and 393 deletions

View File

@@ -26,15 +26,11 @@ func GetExcelData(file multipart.File, dst interface{}, cols []Col) (err error)
// 创建Excel文件对象
f, err := excelize.OpenReader(bytes.NewReader(buf.Bytes()))
if err != nil {
fmt.Println(err)
// c.String(http.StatusInternalServerError, "Excel读取失败")
err = errors.New("Excel读取失败")
return
}
err = ImportExcel(f, dst, 2, cols)
// if err != nil {
// fmt.Println(err)
// }
return err
}
@@ -60,16 +56,6 @@ func ImportBySheet(f *excelize.File, dst interface{}, sheetName string, startRow
return
}
// 获取在数组中得下标
func GetIndex(items []string, item string) int {
for i, v := range items {
if v == item {
return i
}
}
return -1
}
// 解析数据
func importData(f *excelize.File, dst interface{}, sheetName string, startRow int, cols []Col) (err error) {
rows, err := f.GetRows(sheetName) // 获取所有行