完善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

@@ -24,6 +24,26 @@ type Test struct {
Remark string `excel:"name:备注;width:40;"`
}
// func decodeTime(value any) any {
// t, e := core.ParseStringToTsTime(value.(string))
// if e != nil {
// return nil
// }
// return t
// }
var cols = []Col{
{Name: "用户账号", Key: "Id", Width: 15},
{Name: "用户姓名", Key: "Name", Width: 15},
{Name: "用户邮箱", Key: "Email", Width: 15},
{Name: "所属公司", Key: "Com", Width: 20},
{Name: "所在部门", Key: "Dept", Width: 21},
{Name: "角色代码", Key: "RoleKey", Width: 20},
{Name: "角色名称", Key: "RoleName", Width: 25, Replace: map[string]interface{}{"1": "1_超级管理员", "2": "2_普通用户"}},
{Name: "备注", Key: "Remark", Width: 30},
}
// 导出
func TestExport(t *testing.T) {
var testList = []Test{
@@ -32,14 +52,11 @@ func TestExport(t *testing.T) {
{"chiling", "炽翎", "chiling@123.com", "太虚剑派", "行政部", "PTYG", "2", "备注备注备注备注"},
{"yunmo", "云墨", "yunmo@123.com", "太虚剑派", "财务部", "CJGLY", "1", ""},
{"yuelun", "月轮", "yuelun@123.com", "天命科技有限公司", "执行部", "CJGLY", "1", ""},
{"xunyu", "迅羽",
"xunyu@123.com哈哈哈哈哈哈哈哈这里是最大行高测试哈哈哈哈哈哈哈哈这11111111111里是最大行高测试哈哈哈哈哈哈哈哈这里是最大行高测试",
"天命科技有限公司", "开发部", "PTYG", "2",
{"xunyu", "迅羽", "xunyu@123.com哈哈哈哈哈哈哈哈这里是最大行高测试哈哈哈哈", "天命科技有限公司", "开发部", "PTYG", "2",
"备注备注备注备注com哈哈哈哈哈哈哈哈这里是最大行高测试哈哈哈哈哈哈哈哈这里是最大行高测试哈哈哈哈哈哈哈哈这里是最大行高测里是最大行高测试哈哈哈哈哈哈哈哈这里是最大行高测试"},
}
changeHead := map[string]string{"Id": "账号", "Name": "真实姓名"}
//f, err := excel.NormalExport(testList, "Sheet1", "用户信息", "Id,Email,", true, true, changeHead)
f, err := NormalDynamicExport(testList, "Sheet1", "用户信息", changeHead)
f, err := NormalDynamicExport(testList, cols, "Sheet1", "用户信息")
if err != nil {
fmt.Println(err)
return
@@ -58,7 +75,7 @@ func TestImports(t *testing.T) {
fmt.Println("文件打开失败")
}
importList := []Test{}
err = ImportExcel(f, &importList, 2, []Col{})
err = ImportExcel(f, &importList, 2, cols)
if err != nil {
fmt.Println(err)
}