You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
package logic
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
)
|
|
|
|
var savePrefix = "document/"
|
|
var saveSuffix = ".xlsx"
|
|
|
|
func WriteIntoExcelLogic() (savePath string, err error) {
|
|
back, err := GetAllStudentInfoLogic()
|
|
if err != nil {
|
|
return
|
|
}
|
|
f := excelize.NewFile()
|
|
sheetName := "Sheet1"
|
|
f.NewSheet(sheetName)
|
|
headers := []string{"学号", "姓名", "性别", "计分"}
|
|
for i, header := range headers {
|
|
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
|
|
f.SetCellValue(sheetName, cell, header)
|
|
}
|
|
for i, info := range *back {
|
|
row := i + 2
|
|
f.SetCellValue(sheetName, fmt.Sprintf("A%d", row), info.User_id)
|
|
f.SetCellValue(sheetName, fmt.Sprintf("B%d", row), info.User_name)
|
|
f.SetCellValue(sheetName, fmt.Sprintf("C%d", row), info.User_gender)
|
|
f.SetCellValue(sheetName, fmt.Sprintf("D%d", row), info.User_score)
|
|
}
|
|
|
|
currentTime := time.Now()
|
|
formattedTime := currentTime.Format("20060102150405")
|
|
savePath = savePrefix + formattedTime + saveSuffix
|
|
if err = f.SaveAs(savePath); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|