Files
x_admin/docs/server/导入导出excel.md
2024-09-13 16:55:52 +08:00

913 B
Raw Blame History

col结构体

type Col struct {
	Name    string
	Key     string
	Width   int                          // 宽度
	Replace map[string]any               //实现值的替换
	Encode  func(value any) any          //编码函数-导出先Encode后Replace
	Decode  func(value any) (any, error) //解码函数-导入先Replace后Decode
}

使用示例

var cols = []excel2.Col{
		{Name: "标题", Key: "Title", Width: 15},
		{Name: "协议内容", Key: "Content", Width: 15},
		{Name: "排序", Key: "Sort", Width: 15},
		{Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
		{Name: "更新时间", Key: "UpdateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
	}

注意点

  1. Key对应的字段如果是自定义结构体需要实现string接口、或者传递Encode函数

<<< @/../server/util/excel2/excel_test.go#envConfig