mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-12-24 08:12:55 +08:00
28 lines
913 B
Markdown
28 lines
913 B
Markdown
|
||
|
||
col结构体
|
||
```go
|
||
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)
|
||
}
|
||
```
|
||
|
||
使用示例
|
||
```go
|
||
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 |