eorm

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

README

go-eorm: Excel Object Relational Mapping for Go

中文文档

Overview

go-eorm is a powerful Excel Object Relational Mapping library for Go that provides seamless mapping between Excel files and Go structs. It supports both .xls and .xlsx file formats and offers flexible configuration options for complex Excel data structures.

Features

  • Dual Format Support: Read both .xls and .xlsx files using different underlying libraries
  • Hierarchical Title Mapping: Support for multi-level Excel headers using path-like syntax
  • Flexible Type Mapping: Built-in support for string, int64, float64, and bool types
  • Custom Setters: Define custom parsing logic for complex types
  • Array Mapping: Handle multiple columns with the same title path
  • Constraint Validation: Support for required and not_null constraints
  • Merged Cell Handling: Intelligent handling of merged cells in headers
  • Character Escaping: Automatic escaping of special characters in title paths

Installation

go get github.com/stephenfire/go-eorm

Quick Start

Basic Usage
package main

import (
    "reflect"
    "github.com/stephenfire/go-eorm"
)

// Define your struct with eorm tags
type User struct {
    ID     int64  `eorm:"序号//"`
    Name   string `eorm:"名称//"`
    Email  string `eorm:"第一级/邮箱/地址"`
    Age    int64  `eorm:"第一级/年龄/数值"`
    Active bool   `eorm:"状态//"`
}

func main() {
    // Open Excel file
    wb, err := eorm.NewWorkbook("users.xlsx")
    if err != nil {
        panic(err)
    }
    defer wb.Close()

    // Get the first sheet
    sheet, err := wb.GetSheet(0)
    if err != nil {
        panic(err)
    }

    // Create EORM instance
    eorm, err := eorm.NewEORM[User](sheet, reflect.TypeOf(User{}))
    if err != nil {
        panic(err)
    }

    // Iterate through rows
    for eorm.Next() {
        user, err := eorm.Current()
        if err != nil {
            panic(err)
        }
        fmt.Printf("User: %+v\n", user)
    }
}
Advanced Example with Custom Setters
type AdvancedUser struct {
    ID     int64    `eorm:"序号//"`
    Name   string   `eorm:"名称//"`
    Emails []string `eorm:"第一级/邮箱/地址"`
    Tags   []string `eorm:"标签//"`
}

// Custom setter for emails
func (u *AdvancedUser) SetEmails(emails []string) {
    u.Emails = make([]string, len(emails))
    for i, email := range emails {
        u.Emails[i] = "processed_" + email
    }
}

// Custom setter for tags
func (u *AdvancedUser) SetTags(tags []string) {
    u.Tags = tags
}

Title Path System

Basic Syntax

Title paths use / as a delimiter to represent hierarchical Excel headers:

type Example struct {
    Simple   string `eorm:"简单标题"`           // Single-level header
    Nested   string `eorm:"第一级/第二级"`      // Two-level header  
    Deep     string `eorm:"第一级/第二级/第三级"` // Three-level header
}
Key Concepts
  • Delimiter: / - each / represents one additional layer in the Excel header (one more row)
  • Height: The number of layers in a title_path equals the number of separators + 1
  • Consistency: All title_path definitions in the same struct must have the same height, as all columns in a table header have the same height
  • Empty Titles:
    • When title_path starts with / (first title is empty), it skips the first header row, acting as a wildcard for the first row
    • When any layer in title_path is an empty string (""), it preferentially matches the last valid value in the same row (merged cells) or matches empty
Visual Example: Title Path Mapping

Similar to file system paths, title paths use a hierarchical approach to represent Excel columns. The following diagram illustrates how title paths map to Excel headers:

layer titles

Column title_path Description
A 序号// Maps to column A with a two-level header where the first level is "序号" and the second level is empty (merged cell)
B 名称// Maps to column B with a two-level header where the first level is "名称" and the second level is empty (merged cell)
C 第一级/反引号%60测试/空%20格 Maps to column C with a three-level header: "第一级" → "反引号`测试" → "空 格"
D 第一级/反引号%60测试/斜杠%2F Maps to column D with a three-level header: "第一级" → "反引号`测试" → "斜杠/"
E 第一级/双引号%22测试/反斜杠%5C Maps to column E with a three-level header: "第一级" → "双引号"测试" → "反斜杠`
F 第一级/双引号%22测试/第三级 Maps to column F with a three-level header: "第一级" → "双引号"测试" → "第三级"
G 第一级/没有第三级/ Maps to column G with a three-level header: "第一级" → "没有第三级" → empty (merged cell)
Special Characters and Escaping

Special characters in title paths must be escaped using %HH format:

Character Escape Sequence
% %25
' %27
, %2C
" %22
/ %2F
\ %5C
\n %0A
\r %0D
\t %09
` %60
Space %20

Example:

type SpecialChars struct {
    Slash   string `eorm:"第一级/斜杠%2F测试"`
    Backslash string `eorm:"第一级/反斜杠%5C测试"`
    Backtick string `eorm:"第一级/反引号%60测试"`
    Quote   string `eorm:"第一级/双引号%22测试"`
    Space   string `eorm:"第一级/空%20格"`
}

The cmds/pathgener tool can assist you in generating the necessary EORM tags for your Excel files.

Wildcard First Row

Use an empty first title to skip the first header row:

type WildcardExample struct {
    Field string `eorm:"/第二级标题"` // Skips first row, matches second row
}
Array Mapping

When header content may be duplicated, or when wildcards are used in title_path, a single title_path may correspond to multiple columns, resulting in non-unique values. This enables array mapping functionality.

Constraints

Required Constraint

Ensure that a column must exist in the Excel file:

type RequiredExample struct {
    ID   int64  `eorm:"ID,required"`     // Column must exist
    Name string `eorm:"名称,required"`    // Column must exist
}
Not Null Constraint

Ensure that a column exists and contains non-empty values:

type NotNullExample struct {
    ID   int64  `eorm:"ID,not_null"`     // Column must exist and have values
    Name string `eorm:"名称,not_null"`    // Column must exist and have values
}

Configuration Options

Available Options
// Create EORM with options
eorm, err := eorm.NewEORM[User](sheet, reflect.TypeOf(User{}),
    eorm.WithTrimSpace(),              // Trim whitespace from strings
    eorm.WithIgnoreOutOfRange(),       // Ignore out-of-range errors
    eorm.WithIgnoreParseError(),       // Ignore parsing errors
    eorm.WithIgnoreReadRowError(),     // Ignore row reading errors
    eorm.WithFirstRowWildcard(),       // Generate wildcard for first row
    eorm.WithGenLastLayerNoMerged(),   // Generate last layer without merged cells
    eorm.WithTitleStartRow(2),         // Start reading titles from row 2
    eorm.WithMatchLevel(eorm.MatchLevelPerfect),  // Set matching level
)
Matching Levels
  • eorm.MatchLevelNone: Standard matching (default)
  • eorm.MatchLevelMatched: At least a partial match
  • eorm.MatchLevelPerfect: Require exact matches

Error Handling

Common Errors
eorm, err := eorm.NewEORM[User](sheet, reflect.TypeOf(User{}))
if err != nil {
    // Handle initialization errors
}

for eorm.Next() {
    user, err := eorm.Current()
    if err != nil {
        // Handle row processing errors
        if errors.Is(err, eorm.ErrRequiredColumnNotFound) {
            // Handle missing required columns
        }
        if errors.Is(err, eorm.ErrInvalidState) {
            // Handle invalid state
        }
    }
}

if eorm.LastError() != nil {
    // Handle last error
}

File Format Support

XLS Files
  • Uses github.com/shakinm/xlsReader library
  • Supports older Excel format (.xls)
XLSX Files
  • Uses github.com/xuri/excelize/v2 library
  • Supports modern Excel format (.xlsx)

Performance Considerations

  • The library uses reflection for mapping but caches mappings for performance
  • For large files, consider processing rows in batches
  • Use appropriate matching levels to balance performance and accuracy

Testing

The package includes comprehensive tests. Run tests with:

go test ./...

License

Copyright 2025 [email protected]

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

Documentation

Index

Constants

View Source
const (
	ConstraintDefault  = ""
	ConstraintRequired = "required"
	ConstraintNotNull  = "not_null"
)
View Source
const (
	Version   = common.Version(1000)
	Copyright = "Copyright 2025 [email protected]"
)

Variables

View Source
var (
	ErrNotFound         = errors.New("excel: not found")
	ErrOutOfRange       = errors.New("excel: out of range")
	ErrNil              = errors.New("excel: nil")
	ErrEmptyCell        = errors.New("excel: empty cell")
	ErrInvalidValueType = errors.New("excel: invalid value type")
	// ErrInvalidCellValue #NULL!, #DIV/0!, #VALUE!, #REF!, #NAME?, #NUM!!, #N/A
	ErrInvalidCellValue    = errors.New("excel: invalid cell value")
	ErrExcelNotInitialized = errors.New("excel: not initialized")
	ErrEof                 = errors.New("excel: eof")
	ErrParseError          = errors.New("cell value parse error")
)
View Source
var (
	ErrEmptyPath              = errors.New("eorm: empty path")
	ErrUnsupported            = errors.New("eorm: unsupported")
	ErrInvalidState           = errors.New("eorm: invalid state")
	ErrRowNotFound            = errors.New("eorm: row not found")
	ErrRequiredColumnNotFound = errors.New("eorm: required column not found")
	ErrInsufficientMatchLevel = errors.New("eorm: insufficient match level")
)

Functions

func MatchTitlePath

func MatchTitlePath[T any](tree *PathTree[T], sheet Sheet, params *Params) (map[int]T, error)

MatchTitlePath 将excel文件(sheet)中的表头与 tree 所代表的对象属性中定义的映射路径进行匹配, 从而得到 { ColumnIndex : FieldIndex } 的映射关系 returns column index to value mapping

func MatchTitlePathByStream added in v0.2.0

func MatchTitlePathByStream[T any](tree *PathTree[T], stream StreamSheet, params *Params) (map[int]T, error)

func NewRowMapper

func NewRowMapper[T any](objType reflect.Type, sheet Sheet, params *Params) (*RowMapper[T], *PathTree[int], error)

func NewRowMapperByStream added in v0.2.0

func NewRowMapperByStream[T any](objType reflect.Type, stream StreamSheet, params *Params) (*RowMapper[T], *PathTree[int], error)

func NewXlsWorkbookByFile added in v0.2.1

func NewXlsWorkbookByFile(wb xls.Workbook) *xlsWorkbook

func TitleEscape

func TitleEscape(t string) string

func TitleUnescape

func TitleUnescape(t string) (string, error)

Types

type ColumnMapper

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

ColumnMapper 记录对象属性与表格列之间的映射关系

func NewColumnMapper added in v0.2.0

func NewColumnMapper(objType reflect.Type, fieldIdx int, field reflect.StructField, params *Params) (*ColumnMapper, error)

func (*ColumnMapper) CellToField added in v0.2.0

func (m *ColumnMapper) CellToField(rowData reflect.Value, row Row, columnIndexes []int, params *Params) error

CellToField read data from row and set data to mapped object rowData

func (*ColumnMapper) String

func (m *ColumnMapper) String() string

type Constraint

type Constraint string

func (Constraint) IsValid

func (c Constraint) IsValid() bool

func (Constraint) NeedMapper

func (c Constraint) NeedMapper() bool

func (Constraint) NeedValue

func (c Constraint) NeedValue() bool

func (Constraint) String

func (c Constraint) String() string

type EORMReader added in v0.2.0

type EORMReader[T any] struct {
	// contains filtered or unexported fields
}

func NewReader added in v0.2.0

func NewReader[T any](sheet Sheet, objType reflect.Type, opts ...Option) (*EORMReader[T], error)

func (*EORMReader[T]) All added in v0.2.0

func (e *EORMReader[T]) All() iter.Seq2[*T, error]

All 遍历每一行,无论是否有error。无论使用Next()|Current() 还是 All() 或者 NoErrorRows() 只能遍历一次

func (*EORMReader[T]) CheckValue added in v0.2.0

func (e *EORMReader[T]) CheckValue() error

func (*EORMReader[T]) ClrLastError added in v0.2.0

func (e *EORMReader[T]) ClrLastError()

func (*EORMReader[T]) Current added in v0.2.0

func (e *EORMReader[T]) Current() (t *T, err error)

Current 返回当前行的对象

func (*EORMReader[T]) CurrentRowNumber added in v0.2.0

func (e *EORMReader[T]) CurrentRowNumber() (int, bool)

CurrentRowNumber 返回当前行下标,如果-1,则说明尚未开始遍历,如果-2,表示遍历已完成。 第二返回值表示这个值是否在值范围内,这个值为true时则第一返回值返回了遍历过程中当前值所在sheet的行下标

func (*EORMReader[T]) DataStartRow added in v0.2.0

func (e *EORMReader[T]) DataStartRow() int

func (*EORMReader[T]) IsMatched added in v0.2.0

func (e *EORMReader[T]) IsMatched() bool

func (*EORMReader[T]) IsPerfectMatch added in v0.2.0

func (e *EORMReader[T]) IsPerfectMatch() bool

func (*EORMReader[T]) IsValid added in v0.2.0

func (e *EORMReader[T]) IsValid() bool

func (*EORMReader[T]) LastError added in v0.2.0

func (e *EORMReader[T]) LastError() error

func (*EORMReader[T]) Next added in v0.2.0

func (e *EORMReader[T]) Next() bool

Next 移动到下一行,如果还有行则返回true,否则返回false。 无论使用Next()|Current() 还是 All() 或者 NoErrorRows() 只能遍历一次

func (*EORMReader[T]) NoErrorRows added in v0.2.0

func (e *EORMReader[T]) NoErrorRows() iter.Seq2[int, *T]

NoErrorRows 遍历未出错的row,及其在表格中的行号(从0开始,不包括表头)。 无论使用Next()|Current() 还是 All() 或者 NoErrorRows() 只能遍历一次

type EORMWriter added in v0.2.0

type EORMWriter[T any] struct {
	// contains filtered or unexported fields
}

func NewWriter added in v0.2.0

func NewWriter[T any](w SheetWriter, objType reflect.Type, opts ...Option) (*EORMWriter[T], error)

func (*EORMWriter[T]) Append added in v0.2.0

func (w *EORMWriter[T]) Append(objs ...*T) (int, error)

Append write all not nil objects from curRowIndex in input order. returns the number of wrote objects.

func (*EORMWriter[T]) CurrentRowIndex added in v0.2.2

func (w *EORMWriter[T]) CurrentRowIndex() int

func (*EORMWriter[T]) SkipRows added in v0.2.0

func (w *EORMWriter[T]) SkipRows(n int)

type EscapeError

type EscapeError string

func (EscapeError) Error

func (e EscapeError) Error() string

type MappingType

type MappingType byte
const (
	MTString MappingType = iota
	MTInt64
	MTFloat64
	MTBool
	MTStringSlice
	MTInt64Slice
	MTFloat64Slice
	MTBoolSlice
	MTInvalid
)

func NewMappingType

func NewMappingType(typ reflect.Type) (MappingType, error)

func (MappingType) IsSingle

func (mt MappingType) IsSingle() bool

func (MappingType) IsSlice

func (mt MappingType) IsSlice() bool

func (MappingType) IsValid

func (mt MappingType) IsValid() bool

func (MappingType) String

func (mt MappingType) String() string

type MatchLevel

type MatchLevel byte
const (
	MatchLevelNone    MatchLevel = iota // 无要求
	MatchLevelMatched                   // 存在匹配字段即可
	MatchLevelPerfect                   // 类型所有具有"eorm"标签的字段均已找到匹配的列
)

func (MatchLevel) Formalize

func (l MatchLevel) Formalize() MatchLevel

type Option

type Option func(p *Params)

func WithFirstRowWildcard

func WithFirstRowWildcard() Option

func WithGenLastLayerNoMerged

func WithGenLastLayerNoMerged() Option

func WithIgnoreOutOfRange

func WithIgnoreOutOfRange() Option

func WithIgnoreParseError

func WithIgnoreParseError() Option

func WithIgnoreReadRowError

func WithIgnoreReadRowError() Option

func WithMatchLevel

func WithMatchLevel(l MatchLevel) Option

func WithParams

func WithParams(src *Params) Option

func WithTitleStartRow

func WithTitleStartRow(r int) Option

func WithTrimSpace

func WithTrimSpace() Option

func WithWrite added in v0.2.0

func WithWrite() Option

type Params

type Params struct {
	TrimSpace              bool       // 是否删除首尾空格,缺省不删除
	IgnoreOutOfRange       bool       // 越界时认为是零值,而不报错
	IgnoreReadRowError     bool       // 迭代sheet的row时,如果出错是否跳过
	IgnoreParseError       bool       // 遇到 ErrParseError 时当作无值处理
	GenWildcardForFirstRow bool       // 生成 TitlePath 时,通配第一行title
	GenLastRowNoMerged     bool       // 生成TitlePath时,最后一行的空不认为是横向合并
	TitleStartRow          int        // 从哪一行(行号从0开始)开始分析title_path, 所有小于0的值均被认为是0
	RequiredMatchLevel     MatchLevel // 需要类型与excel表头的匹配程度,无论何值,tag.constraint的要求必须达成
	Writable               bool       // 是否可写
}

func NewParams

func NewParams(opts ...Option) *Params

func (*Params) CopyFrom

func (p *Params) CopyFrom(src *Params) *Params

func (*Params) MinRows

func (p *Params) MinRows(titleDepth int) int

type PathTree

type PathTree[T any] struct {
	// contains filtered or unexported fields
}

PathTree 以 root 为根节点的路径树,所有叶子节点都有值,而值类型为 T。树的所有分支深度都为 depth。 实际使用时,PathTree = { TitlePath : FieldIndex }, 也就是以在属性tag中定义的表头路径为键,以该属性在对象中的属性下标为值的键值对。

func (*PathTree[T]) Check

func (p *PathTree[T]) Check() (depth int, err error)

func (*PathTree[T]) Depth

func (p *PathTree[T]) Depth() int

func (*PathTree[T]) Put

func (p *PathTree[T]) Put(val T, path TitlePath) error

Put 将 path 所代表的路径,按层级放入树中,并在叶子节点记录 val 值。 实际使用中,val 记录的是映射对象的属性下标

type Row

type Row interface {
	ColumnCount() int
	GetColumn(index int) (string, error)
	GetInt64Column(index int) (int64, error)
	GetFloat64Column(index int) (float64, error)
	GetBoolColumn(index int) (bool, error)
	AllColumns() iter.Seq2[int, string]
}

Row excel表格中一行数据的抽象类型接口

type RowMapper

type RowMapper[T any] struct {
	// contains filtered or unexported fields
}

RowMapper RowMapper[T]对象的主要功能是把Row转换为一个类型为*T的对象。其中:

* RowMapper.typ属性是T类型的reflect.Type。 * RowMapper.fields保存所有类型T中所有需要映射的属性和信息ColumnMapper * RowMapper.columns保存T中每一个需要映射的属性值需要由Row中哪些列的值构成。

ColumnMapper中保存了属性值的构成方法,分为两种:

* 当ColumnMapper.HasSetter==false时,直接赋值给属性值 * 当ColumnMapper.HasSetter==true时,通过ColumnMapper.Setter保存的*T的方法设置属性值。

无论是哪种方式,值的类型都保存在ColumnMapper.fieldType中,而值类型的Kind()只能是string, int64, float64, bool, []string, [] int64, []float64, []bool之一。

转换方法为RowMapper.Transit(row Row) (*T, error)方法,其步骤为:

  1. 遍历由对象属性fieldIndex到Row中列columnIndexes的映射表RowMapper.columns,当映射到多列时,也就是len(columnIndexes)> 1,值类型必须是[]string, []int64, []float64, []bool之一。
  2. 遍历columnIndexes,从row中获取各列对应的值,并转换为ColumnMapper.fieldType的类型,得到fieldValue
  3. 创建RowMapper.typ类型对应的指针对象rowData
  4. 当ColumnMapper.HasSetter==false时,将fieldValue直接赋值给rowData对应index为fieldIndex的属性
  5. 当ColumnMapper.HasSetter==true时,将fieldValue传递给rowData对象对应的ColumnMapper.Setter方法,完成值设置。
  6. 返回新创建的rowData

func (*RowMapper[T]) IsMatched

func (m *RowMapper[T]) IsMatched() bool

IsMatched 对象中至少有一个属性找到了对应列

func (*RowMapper[T]) IsPerfectMatch

func (m *RowMapper[T]) IsPerfectMatch() bool

IsPerfectMatch 对象每一个属性都找到了对应列

func (*RowMapper[T]) Transit

func (m *RowMapper[T]) Transit(row Row) (*T, error)

func (*RowMapper[T]) Write added in v0.2.0

func (m *RowMapper[T]) Write(w SheetWriter, rowIndex int, obj *T) error

type Sheet

type Sheet interface {
	GetName() string
	RowCount() int
	GetRow(index int) (Row, error)
}

Sheet excel中一个表格的抽象类型接口,可随机读取表格中的行内容

type SheetWriter added in v0.2.0

type SheetWriter interface {
	GetSheetName() string
	// Write write value to the cell(row, column), where both row and column start with 0.
	// The valid value types are int64, float64, string, and bool.
	Write(row, column int, value any) error
	// Stream get StreamSheet of current sheet
	Stream() (StreamSheet, error)
}

SheetWriter used to write ORM object to excel sheet

type StreamSheet added in v0.2.0

type StreamSheet interface {
	Next() bool
	Current() (Row, error)
	CurrentRowNumber() int
	Skip(rowCount int) error
	Close() error
}

StreamSheet 通过stream模式读取row data的Sheet,在使用完打开的 StreamSheet 之前不应关闭 Workbook。只能按顺序遍历。

type TitleLayer

type TitleLayer[T any] struct {
	// contains filtered or unexported fields
}

TitleLayer 从 PathTree 的根开始,带有传承的记录每一级根据列内容匹配的列和对应的节点 当 key == -1 时,表示所有列都匹配的节点。初始化时的值为 {-1: root}. 使用 PathTree 与实际excel文件表头进行匹配得到 { excel列下表ColumnIndex : 映射对象对应属性下标FieldIndex } 对应关系的过程中, 用 TitleLayer 记录从文件表头自顶向下,每一行匹配后 ColumnIndex 与 PathTree中对应层级的 TreeItem 之间的对应关系。

func NewTitleLayer

func NewTitleLayer[T any](root TreeItem[T]) *TitleLayer[T]

func (*TitleLayer[T]) At

func (m *TitleLayer[T]) At(index int) (TreeItem[T], bool)

func (*TitleLayer[T]) IsRoot

func (m *TitleLayer[T]) IsRoot() bool

func (*TitleLayer[T]) NextRow

func (m *TitleLayer[T]) NextRow(row Row) (*TitleLayer[T], error)

func (*TitleLayer[T]) Size

func (m *TitleLayer[T]) Size() int

func (*TitleLayer[T]) Values

func (m *TitleLayer[T]) Values() (map[int]T, error)

type TitlePath

type TitlePath []string

TitlePath 用来指定在多级(包括单级)表头中的路径,从而确定指向的列。

func MustTitlePath

func MustTitlePath(path string) TitlePath

func (TitlePath) Clone

func (tp TitlePath) Clone() TitlePath

func (TitlePath) Decode

func (tp TitlePath) Decode(namepath string) (TitlePath, error)

func (TitlePath) Encode

func (tp TitlePath) Encode() string

func (TitlePath) Last

func (tp TitlePath) Last() string

func (TitlePath) String

func (tp TitlePath) String() string

func (TitlePath) Truncate

func (tp TitlePath) Truncate(n int) TitlePath

type TitlePaths

type TitlePaths []TitlePath

func BuildTitlePaths

func BuildTitlePaths(sheet Sheet, depth int, opts ...Option) (TitlePaths, error)

func (TitlePaths) Info

func (tps TitlePaths) Info() string

type TreeItem

type TreeItem[T any] interface {
	IsValue() bool
	HasValue() bool
	GetValue() T
	IsBranch() bool
	HasChild(title string) bool
	GetChild(title string) TreeItem[T]
	SetChild(title string, child TreeItem[T]) error
	ChildrenKeys() []string
	Depth() (int, error)
}

TreeItem 只支持由上而下的树状结构构建的表头,每一个TreeItem都有其明确的父节点

type Workbook

type Workbook interface {
	SheetCount() int
	GetSheet(index int) (Sheet, error)
	GetSheetByName(name string) (Sheet, error)
	GetStreamSheet(index int) (StreamSheet, error)
	GetStreamSheetByName(name string) (StreamSheet, error)
	GetSheetWriter(index int) (SheetWriter, error)
	GetSheetWriterByName(name string) (SheetWriter, error)
	Save() error
	WriteTo(w io.Writer) (int64, error)
	Close() error
}

Workbook excel文件的抽象接口类型

func NewWorkbook

func NewWorkbook(filePath string) (Workbook, error)

func NewWorkbookByReadSeeker

func NewWorkbookByReadSeeker(filename string, reader io.ReadSeeker) (Workbook, error)

func NewXlsWorkbook

func NewXlsWorkbook(filePath string) (Workbook, error)

func NewXlsWorkbookByReadSeeker

func NewXlsWorkbookByReadSeeker(reader io.ReadSeeker) (Workbook, error)

func NewXlsxWorkbook

func NewXlsxWorkbook(filePath string) (Workbook, error)

func NewXlsxWorkbookByFile added in v0.2.1

func NewXlsxWorkbookByFile(f *excelize.File) (Workbook, error)

func NewXlsxWorkbookByReadSeeker

func NewXlsxWorkbookByReadSeeker(reader io.ReadSeeker) (Workbook, error)

type XlsCell

type XlsCell struct{}

func (XlsCell) IsBlank

func (x XlsCell) IsBlank(data structure.CellData) bool

func (XlsCell) IsBool

func (x XlsCell) IsBool(data structure.CellData) bool

func (XlsCell) IsFloat

func (x XlsCell) IsFloat(data structure.CellData) bool

func (XlsCell) IsInt

func (x XlsCell) IsInt(data structure.CellData) bool

func (XlsCell) IsString

func (x XlsCell) IsString(data structure.CellData) bool

func (XlsCell) ToBool

func (x XlsCell) ToBool(data structure.CellData) (bool, error)

func (XlsCell) ToFloat64

func (x XlsCell) ToFloat64(data structure.CellData) (float64, error)

func (XlsCell) ToInt64

func (x XlsCell) ToInt64(data structure.CellData) (int64, error)

func (XlsCell) ToString

func (x XlsCell) ToString(data structure.CellData) (string, error)

func (XlsCell) Type

func (x XlsCell) Type(data structure.CellData) XlsCellType

type XlsCellType

type XlsCellType byte
const (
	XlsCellBlank     XlsCellType = iota // empty cell
	XlsCellBoolOrErr                    // boolean value or error
	XlsCellFake                         // fake, not exist. like a placeholder
	XlsCellString                       // string value
	XlsCellFloat                        // float64
	XlsCellInt                          // int64
	XlsCellNil
	XlsCellUnknown
)

Directories

Path Synopsis
cmds
pathgener command

Jump to

Keyboard shortcuts

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