l_excel_export/export_test.go

72 lines
2.0 KiB
Go

package excel_export
import (
"fmt"
"github.com/xuri/excelize/v2"
"os"
"testing"
)
func TestExport(t *testing.T) {
f, err := excelize.OpenFile("./a.xlsx")
if err == os.ErrNotExist {
fmt.Println(111)
}
_ = fmt.Sprint(f, err)
}
type Order struct {
OrderNum string `json:"order_num"`
OrderID int `json:"order_id"`
CusNum string `json:"cus_num"`
}
func TestData(t *testing.T) {
var c = []interface{}{
Order{OrderNum: "aasdsad", OrderID: 1, CusNum: "hghghfg"},
Order{OrderNum: "vqewqewq", OrderID: 2, CusNum: "iuyiuyiyu"},
Order{OrderNum: "adfgf", OrderID: 3, CusNum: "ewewew"},
Order{OrderNum: "abbbb", OrderID: 4, CusNum: "xcxcxc"},
Order{OrderNum: "aqwewqeqw", OrderID: 5, CusNum: "fdfdfd"},
Order{OrderNum: "ahhhhhh", OrderID: 6, CusNum: "asdadsa"},
Order{OrderNum: "vvvvv", OrderID: 7, CusNum: "vcvcv"},
Order{OrderNum: "aaaa", OrderID: 8, CusNum: "asdasdwqewqe"},
Order{OrderNum: "wwww", OrderID: 9, CusNum: "bvbvbvbvbv"},
Order{OrderNum: "ffff", OrderID: 10, CusNum: "gfgfgf"},
Order{OrderNum: "tttt", OrderID: 11, CusNum: "zxczczxczxczx"},
Order{OrderNum: "hhhh", OrderID: 12, CusNum: "gjhfgjghjgh"},
Order{OrderNum: "bbvbv", OrderID: 13, CusNum: "ytytytuty"},
Order{OrderNum: "zcxzczx", OrderID: 14, CusNum: "rqwrqrqrqrqr"},
Order{OrderNum: "asdasd", OrderID: 15, CusNum: "asdzczxfaxc"},
}
out := NewExport(WithJobName("a"))
task_id, err := out.Run(&Config{
FileName: "a",
Data: c,
Ext: Xlsx,
Head: []*FiledMapping{
{FieldName: "order_num", ColName: "订单编号"},
{FieldName: "order_id", ColName: "订单id"},
{FieldName: "cus_num", ColName: "顾客编号 "},
},
SavePath: "./path",
})
if err != nil {
panic(err)
}
fmt.Println(task_id)
select {}
}
func TestTaskInfo(t *testing.T) {
out, err := NewExport(WithJobName("a")).TaskInfo("1740733651965395783")
fmt.Println(out, err)
}
func TestTaskHis(t *testing.T) {
out, err := NewExport(WithJobName("a")).TaskHis(1, 2)
fmt.Println(out, err)
}