fonchain-fiee/pkg/service/bundle/logic/export.go

43 lines
1.2 KiB
Go
Raw Normal View History

2025-05-09 03:12:33 +00:00
package logic
import (
"errors"
"fmt"
"fonchain-fiee/pkg/service/bundle/common"
"time"
"github.com/360EntSecGroup-Skylar/excelize"
)
func WriteToExcel(dirPath string, orderInfos [][]interface{}) (string, error) {
headRow := []interface{}{"订单编号", "用户编号", "姓名", "性别", "手机号", "国籍", "套餐名称", "签署时间", "套餐费用", "增值服务视频条数", "增值金额", "总额", "支付状态", "支付时间", "财务确认状态"}
xlsx := excelize.NewFile()
index := "Sheet1"
style, _ := xlsx.NewStyle(`{"alignment":{
"horizontal":"center"
}}`)
xlsx.SetCellStyle(index, "A1", "A1", style)
2025-05-09 09:01:51 +00:00
xlsx.SetSheetRow(index, "A1", &headRow)
2025-05-09 03:12:33 +00:00
2025-05-09 09:01:51 +00:00
rowIndex := 2
2025-05-09 03:12:33 +00:00
for i := 0; i < len(orderInfos); i++ {
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", rowIndex), fmt.Sprintf("M%v", rowIndex), style)
xlsx.SetSheetRow(index, fmt.Sprintf("A%v", rowIndex), &orderInfos[i])
rowIndex++
}
//path := dirPath + "/" + artShowInfo.ArtistName + "-" + artShowInfo.ShowSeq + "-price" + ".xlsx"
2025-05-09 08:32:25 +00:00
path := dirPath + "/orderInfo_" + time.Now().Format("20060102150405") + ".xlsx"
2025-05-09 03:12:33 +00:00
err := xlsx.SaveAs(path)
if err != nil {
fmt.Println("save rows err :", err)
return "", errors.New(common.ErrorExportOrderInfo)
}
return path, nil
}