import "github.com/360EntSecGroup-Skylar/excelize"
func getExcelData(f *excelize.File) error {
filePath := `./static`
count := getCount()
frequency := (count / SIZE) + 1
log.Println("要分为", frequency, "个excel表格")
for i := 0; i < frequency; i++ {
values, err := getAllData(SIZE, i * SIZE) //分页
if err != nil {
return err
}
results := values["list"].([]Result)
for index, c := range results {
if index == 0 {
//表头
f.SetSheetRow("Sheet1", "A1", &[]interface{}{
"ID", "字段x", "字段x", "字段x", "字段x",
})
}
lint := strconv.Itoa(index + 2)
f.SetSheetRow("Sheet1", "A"+lint, &[]interface{}{
c.Id, c.字段x, c.字段x, c.字段x, c.字段x,
})
}
nowTime := time.Now().Format("2006-01-02_15_04_05")
filename := filePath + "./client-" + nowTime + fmt.Sprintf("%04d", i) + ".xlsx"
// Save xlsx file by the given path.s
if err = f.SaveAs(filename); err != nil {
return err
}
}
return nil
}