Documentation
¶
Index ¶
- func GetExcelColName(i int) string
- type ExcelField
- type ExcelHandler
- func (r *ExcelHandler[T]) AddError(err string, val string)
- func (o *ExcelHandler[T]) CvtDataValue(column ExcelField, value string) (any, error)
- func (w *ExcelHandler[T]) GetFieldValue(record any, field ExcelField) any
- func (r *ExcelHandler[T]) ParseExcelContent(content string, handler func(record T)) []T
- func (o *ExcelHandler[T]) ValidateHeaders(headers []string)
- func (w *ExcelHandler[T]) WriteExcel(data []T, filename string, sheet string) (*excelize.File, error)
- func (w *ExcelHandler[T]) WriteExcelFile(data []T, f *excelize.File, sheet string) error
- type IExcelHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetExcelColName ¶
Types ¶
type ExcelField ¶
type ExcelField struct {
Header string // 表头
FieldName string // 字段名称
DataType string // 数据类型
// 导出字段
FKProp string // 外键字段对应要导出的数据
Width int // 写入Excel时的列宽
Format string // 导出时的格式化字符串
// 导入字段
Required bool // 从excel解析时验证是否必填
AllowScientificNumber bool // 从excel解析时是否允许科学计数值
DefaultValue string // 表格中未填写时使用的值
}
type ExcelHandler ¶
type ExcelHandler[T any] struct { Sub IExcelHandler[T] // 模拟继承,看作子类实例 Fields []ExcelField Errors map[string][]string // 数据错误 Warnings map[string][]string // 数据警告 }
Excel处理器,用于导入导出
func NewExcelHandler ¶
func NewExcelHandler[T any]() *ExcelHandler[T]
func (*ExcelHandler[T]) AddError ¶
func (r *ExcelHandler[T]) AddError(err string, val string)
func (*ExcelHandler[T]) CvtDataValue ¶
func (o *ExcelHandler[T]) CvtDataValue(column ExcelField, value string) (any, error)
func (*ExcelHandler[T]) GetFieldValue ¶
func (w *ExcelHandler[T]) GetFieldValue(record any, field ExcelField) any
func (*ExcelHandler[T]) ParseExcelContent ¶
func (r *ExcelHandler[T]) ParseExcelContent(content string, handler func(record T)) []T
func (*ExcelHandler[T]) ValidateHeaders ¶
func (o *ExcelHandler[T]) ValidateHeaders(headers []string)
func (*ExcelHandler[T]) WriteExcel ¶
func (*ExcelHandler[T]) WriteExcelFile ¶
func (w *ExcelHandler[T]) WriteExcelFile(data []T, f *excelize.File, sheet string) error
type IExcelHandler ¶
type IExcelHandler[T any] interface { GetExcelFields() GetFieldValue(record T, field ExcelField) any // 导入时转换数据 CvtDataValue(column ExcelField, value string) (any, error) }
Click to show internal directories.
Click to hide internal directories.