excelp

package module
v0.0.0-...-88b9102 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

excelp

string

    readContext := excelp.ExcelRead().
        Url("./excelp_demo.xlsx").
        Sheet("Sheet1").
        MinCol(3).// 给row 设置最小列数,填充默认空字符
        Skip(1) //跳过第一行
    
    defer readContext.Close()
    
    excelp.Read(readContext, func(index int, row []string) error {
        fmt.Println(index, row)
        return nil
    })


struct
    type User struct {
        ID   types.UUID `json:"id"  tableName:"public.t_user"`
        Name string     `json:"info"`
        Age  int        `json:"age"`
    }

    
    readContext := excelp.ExcelRead().
        Url("./excelp_demo.xlsx").
        Sheet("Sheet1").
        MinCol(3).
        Skip(1) //跳过第一行
    
    defer readContext.Close()
    
	err := excelp.ReadModel[User](readContext, func(index int, row []string, user User, e []excelp.CellErr) error {
		if len(e) > 0 {
			bytes, _ := json.Marshal(e)
			fmt.Println(index, string(bytes))
		} else {
			bytes, _ := json.Marshal(user)
			fmt.Println(index, string(bytes))
		}
		return nil //这里返回err,ReadModel会在读取新一行前,检查err并返回
	})
	if err != nil {
		fmt.Println(err)
	}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNil          = errors.New("nil")
	ErrContainEmpty = errors.New("slice empty")

	ErrExcelPStop          = errors.New("excelp stop")            // excelp 停止解析
	ErrExcelPIndexNotFound = errors.New("excelp index not found") // excelp 字段index,找不到
)
View Source
var TimeFormat = map[int]*excelize.Style{
	0: {NumFmt: 0},
	1: {CustomNumFmt: types.NewString("yyyy-mm-dd")},
	2: {CustomNumFmt: types.NewString("HH:mm:ss")},
	3: {CustomNumFmt: types.NewString("yyyy-mm-dd HH:mm:ss")},
}

Functions

func Read

func Read(
	c *ExcelReadContext,
	fun func(index int, row []string, err []CellErr) error,
) error

func ReadModel

func ReadModel[T any](
	c *ExcelReadContext,
	fun func(index int, row []string, t T, err []CellErr) error,
) error

func Write

func Write(c *ExcelWriteContext, col []string) error

func WriteModel

func WriteModel[T any](t T) error

Types

type CellErr

type CellErr struct {
	Err   string // 错误信息
	Col   string // 列
	Row   int    // 行
	Value string // excel cell 值
}

func (CellErr) IsRequiredErr

func (e CellErr) IsRequiredErr() bool

func (CellErr) ToExcelCellName

func (e CellErr) ToExcelCellName() string

type ExcelReadContext

type ExcelReadContext struct {
	// contains filtered or unexported fields
}

func ExcelRead

func ExcelRead() *ExcelReadContext

func (*ExcelReadContext) Close

func (c *ExcelReadContext) Close() error

Close 关闭文件

func (*ExcelReadContext) ColNum

func (c *ExcelReadContext) ColNum(num int) *ExcelReadContext

ColNum 设置 列数,当列数不足,会填充空字符串

func (*ExcelReadContext) Convert

func (c *ExcelReadContext) Convert(fun func(index int, col []string) ([]string, error)) *ExcelReadContext

Convert 行转换函数

func (*ExcelReadContext) ConvertCell

func (c *ExcelReadContext) ConvertCell(col string, fun func(col string) (string, error)) *ExcelReadContext

col 列名,列转化函数

func (*ExcelReadContext) DateCol

func (c *ExcelReadContext) DateCol(col ...string) *ExcelReadContext

DateCol 设置为时间格式 yyyy-MM-dd

func (*ExcelReadContext) DateTimeCol

func (c *ExcelReadContext) DateTimeCol(col ...string) *ExcelReadContext

DateTimeCol 设置为时间格式 yyyy-MM-dd HH:mm:ss

func (*ExcelReadContext) EnableAsync

func (c *ExcelReadContext) EnableAsync(maxWorkers int, queueSize int, rejectPolicy lcore.RejectPolicy) *ExcelReadContext

EnableAsync 启用异步

func (*ExcelReadContext) Panic

func (c *ExcelReadContext) Panic() *ExcelReadContext

func (*ExcelReadContext) Sheet

func (c *ExcelReadContext) Sheet(sheet string) *ExcelReadContext

func (*ExcelReadContext) Skip

func (c *ExcelReadContext) Skip(num int) *ExcelReadContext

Skip 跳过几行

func (*ExcelReadContext) SkipEmpty

func (c *ExcelReadContext) SkipEmpty() *ExcelReadContext

SkipEmpty 跳过空行

func (*ExcelReadContext) TimeCol

func (c *ExcelReadContext) TimeCol(col ...string) *ExcelReadContext

TimeCol 设置为时间格式 yyyy-MM-dd HH:mm:ss

func (*ExcelReadContext) Url

type ExcelWriteContext

type ExcelWriteContext struct {
	// contains filtered or unexported fields
}

func ExcelWrite

func ExcelWrite() *ExcelWriteContext

func (*ExcelWriteContext) Remove

func (c *ExcelWriteContext) Remove() error

Remove 删除临时文件

func (*ExcelWriteContext) Save

func (c *ExcelWriteContext) Save() (string, error)

Save 关闭文件,返回文件路径

func (*ExcelWriteContext) Sheet

func (c *ExcelWriteContext) Sheet(sheet string) *ExcelWriteContext

func (*ExcelWriteContext) Skip

func (c *ExcelWriteContext) Skip(num int) *ExcelWriteContext

Skip 跳过几行

func (*ExcelWriteContext) Template

func (c *ExcelWriteContext) Template(path string) *ExcelWriteContext

type Field

type Field struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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