gexcel

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DatePattern        = "2006-01-02"
	DateTimePattern    = "2006-01-02 15:04:05"
	TagCustomKey       = "gxlsx"
	TagCustomTitleKey  = "title"
	TagCustomIndexKey  = "index"
	TagCustomFormatKey = "format"
)

Variables

This section is empty.

Functions

func ReadFileStreamToList

func ReadFileStreamToList[T any](r io.Reader, sheetIndex int) (resultData []T, err error)

ReadFileStreamToList

@Description: 读取文件流
@param r 文件流
@param sheetIndex 需要读取第几个单元薄
@param ptr 读取后的切片对象
@return resultData 返回的切片
@return err 错误信息

func ReadFileToList

func ReadFileToList[T any](filePath string, sheetIndex int) (resultData []T, err error)

ReadFileToList

@Description:读取本地文件至切片
@param filePath 本地文件的路径
@param sheetIndex 需要读取第几个单元薄
@return resultData 返回的切片
@return err 错误信息

func WriteToFile

func WriteToFile[T any](n string, dataList []T) (*excelize.File, error)

WriteToFile

@Description: 将二维数组数据写入到excel的sheet
@param n 单元薄的名称
@param dataList 数据切片
@return *excelize.File 返回的excelFile对象
@return error 错误信息

Types

type Callback

type Callback func(maps map[string]interface{}) error

Callback /** 定义回调函数

type ExcelFields

type ExcelFields struct {
	Title     string            //名称
	Index     int               //索引,从0开始
	Format    string            //所以的格式化类型(datetime),没有标注的话,默认是属性的类型
	Name      string            //json字段名称
	FieldType string            //字段类型
	Tags      map[string]string //保存所有tags
}

ExcelFields /**Excel的字段属性

type ExcelStruct

type ExcelStruct struct {
	MapIndex       map[int]string         //按照index排序的map
	IndexMax       int                    //列index最大值
	Fields         map[string]ExcelFields //所有字段
	StartRow       int                    //第几行开始为具体数据
	Err            error                  //错误
	ConvertTypeErr bool                   //类型转换时候,产生错误时是否直接提示报错
}

ExcelStruct /** 封装对象

func NewExcelStruct

func NewExcelStruct(StartRow, IndexMax int, fastErr bool) *ExcelStruct

NewExcelStruct

@Description:
@param StartRow 开始行,索引从0开始
@param IndexMax 索引最大行,如果结构体中的index大于配置的,那么使用结构体中的
@param fastErr
@return *ExcelStruct

func NewExcelStructDefault

func NewExcelStructDefault() *ExcelStruct

NewExcelStructDefault

@Description: 创建读取的结构体 默认,从第一行开始,索引从 0开始
@return *ExcelStruct

func (*ExcelStruct) Row

func (c *ExcelStruct) Row(row []string) (map[string]interface{}, error)

Row /** 处理一行的数据,将行数据根据index转换成map

func (*ExcelStruct) RowsAllProcess

func (c *ExcelStruct) RowsAllProcess(rows [][]string, callback Callback) error

RowsAllProcess /** 处理sheet的rows

func (*ExcelStruct) RowsProcess

func (c *ExcelStruct) RowsProcess(rows [][]string, callback Callback) error

RowsProcess /** 处理函数

func (*ExcelStruct) SetPointerStruct

func (c *ExcelStruct) SetPointerStruct(ptr interface{}) *ExcelStruct

SetPointerStruct /** 设置并构造转换的结构体

type FieldsModel

type FieldsModel struct {
	Err    error                  //错误
	Fields map[string]ExcelFields //所有字段
	// index sort
	MapIndex map[int]string //按照 index 排序
	//max index
	IndexMax int // index 最大
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL