Documentation
¶
Index ¶
Constants ¶
const ( // TagTabular is the struct tag name for tabular field configuration. TagTabular = "tabular" // Tag attributes for field configuration. AttrDive = "dive" // Recursively parse embedded struct AttrName = "name" // Column name (header) AttrWidth = "width" // Column width (for display/export hints) AttrOrder = "order" // Column order AttrDefault = "default" // Default value for import AttrFormat = "format" // Format template (date/number format) AttrFormatter = "formatter" // Custom formatter name for export AttrParser = "parser" // Custom parser name for import // Special tag value. IgnoreField = "-" // Ignore this field )
Variables ¶
var ErrUnsupportedType = errors.New("unsupported type")
ErrUnsupportedType indicates the target type is not supported by the parser.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
Index []int // Field index path in the struct
Name string // Column name (header)
Width float64 // Column width hint (for display/export)
Order int // Column order (for sorting)
Default string // Default value used during import when cell is empty
Format string // Format template (e.g., date format, number format)
Formatter string // Custom formatter name for export
Parser string // Custom parser name for import
}
Column represents metadata for a single column in tabular data.
type ExportError ¶
ExportError represents an error that occurred during data export. Row is 0-based data row index.
func (ExportError) Error ¶
func (e ExportError) Error() string
Error implements the error interface.
func (ExportError) Unwrap ¶
func (e ExportError) Unwrap() error
Unwrap returns the underlying error.
type Exporter ¶
type Exporter interface {
// RegisterFormatter registers a custom formatter with the given name.
RegisterFormatter(name string, formatter Formatter)
// ExportToFile exports data to an Excel file.
ExportToFile(data any, filename string) error
// Export exports data to a bytes.Buffer.
Export(data any) (*bytes.Buffer, error)
}
Exporter defines the interface for exporting tabular data. It provides methods to write and format tabular data to various destinations.
type Formatter ¶
type Formatter interface {
// Format converts a Go value to a cell string
Format(value any) (string, error)
}
Formatter defines the interface for custom value formatters. Formatters convert Go values to cell strings during export.
func NewDefaultFormatter ¶
NewDefaultFormatter creates a default formatter with optional format template.
type ImportError ¶
ImportError represents an error that occurred during data import. Row is 1-based and includes the header row.
func (ImportError) Error ¶
func (e ImportError) Error() string
Error implements the error interface.
func (ImportError) Unwrap ¶
func (e ImportError) Unwrap() error
Unwrap returns the underlying error.
type Importer ¶
type Importer interface {
// RegisterParser registers a custom parser with the given name.
RegisterParser(name string, parser ValueParser)
// ImportFromFile imports data from an Excel file.
ImportFromFile(filename string) (any, []ImportError, error)
// Import imports data from an io.Reader.
Import(reader io.Reader) (any, []ImportError, error)
}
Importer defines the interface for importing tabular data. It provides methods to read and parse tabular data from various sources.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema contains the pre-parsed tabular metadata for a struct type.
func NewSchemaFor ¶
NewSchemaFor creates a Schema instance from type T.
func (*Schema) ColumnCount ¶
ColumnCount returns the number of columns.
func (*Schema) ColumnNames ¶
ColumnNames returns all column names.
type ValueParser ¶
type ValueParser interface {
// Parse converts a cell string to a Go value
Parse(cellValue string, targetType reflect.Type) (any, error)
}
ValueParser defines the interface for custom value parsers. Parsers convert cell strings to Go values during import.
func NewDefaultParser ¶
func NewDefaultParser(format string) ValueParser
NewDefaultParser creates a default parser with optional format template.