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

28 lines
913 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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