Documentation
¶
Index ¶
- Variables
- type Axis
- type Container
- type Excel
- func (e *Excel) GetSheetIndex() int
- func (e *Excel) GetSheetName() string
- func (e *Excel) Marshal(container any, tags ...map[string]*Tags) error
- func (e *Excel) SetAxis(axis string)
- func (e *Excel) SetAxisCoordinates(col int, row int)
- func (e *Excel) SetSheetIndex(index int)
- func (e *Excel) SetSheetName(sheet string)
- func (e *Excel) Unmarshal(container any, tags ...map[string]*Tags) error
- type Field
- func (f *Field) GetReadColumnName() string
- func (f *Field) GetReadDefault() interface{}
- func (f *Field) GetReadEncoding() string
- func (f *Field) GetReadFormat() string
- func (f *Field) GetReadIgnore() bool
- func (f *Field) GetReadRequired() bool
- func (f *Field) GetReadSplit() string
- func (f *Field) GetWriteColumnName() string
- func (f *Field) GetWriteDefault() interface{}
- func (f *Field) GetWriteEncoding() string
- func (f *Field) GetWriteFormat() string
- func (f *Field) GetWriteIgnore() bool
- func (f *Field) GetWriteRequired() bool
- func (f *Field) GetWriteSplit() string
- type Fields
- type IReadTags
- type IReader
- type ITags
- type IWriteTags
- type IWriter
- type MapWriter
- type Marshaller
- type Reader
- type Sheet
- type SliceReader
- type SliceWriter
- type Struct
- type StructReader
- type StructWriter
- type Tags
- type Unmarshaller
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( ErrFileIsNil = errors.New("excel: the file is nil") ErrSheetNotValid = errors.New("excel: the sheet name is not valid") ErrAxisNotValid = errors.New("excel: the axis is not valid") ErrConfigNotValid = errors.New("excel: the configuration is not valid") ErrMapKeyNotString = errors.New("excel: the map key must be a string") ErrNoReaderFound = errors.New("excel: unable to create an appropriate reader") ErrNoWriterFound = errors.New("excel: unable to create an appropriate writer") ErrContainerNotSlice = errors.New("excel: the Container must be a slice") ErrContainerNotMap = errors.New("excel: the Container must be a map") ErrContainerInvalid = errors.New("excel: the Container must be a slice or a pointer") ErrColumnRequired = errors.New("excel: required colum") ErrNotImplemented = errors.New("excel: not implemented") )
Functions ¶
This section is empty.
Types ¶
type Container ¶ added in v0.4.0
Container is a struct that contains the Value and type of the container it is used to create the appropriate reader or writer
type Excel ¶
func (*Excel) GetSheetIndex ¶
GetSheetIndex gets the sheet index used by the reader or writer
func (*Excel) GetSheetName ¶
GetSheetName gets the sheet name used by the reader or writer
func (*Excel) SetAxisCoordinates ¶
SetAxisCoordinates sets the axis coordinates to be used by the reader or writer
func (*Excel) SetSheetIndex ¶
SetSheetIndex sets the sheet index to be used by the reader or writer
func (*Excel) SetSheetName ¶
SetSheetName sets the sheet name to be used by the reader or writer
type Field ¶ added in v0.4.0
type Field struct {
Name string
Index int
Type reflect.Type
MainTags *Tags // mainTags used by default
ReadTags *Tags // mainTags for reading
WriteTags *Tags // mainTags for writing
}
Field is a struct used to store the information of a field of a struct
func (*Field) GetReadColumnName ¶ added in v0.4.0
GetReadColumnName returns the column name to read from the excel file
func (*Field) GetReadDefault ¶ added in v0.4.0
func (f *Field) GetReadDefault() interface{}
GetReadDefault returns the default value to use if the cell is empty
func (*Field) GetReadEncoding ¶ added in v0.4.0
GetReadEncoding returns the encoding to use when reading the cell
func (*Field) GetReadFormat ¶ added in v0.4.0
GetReadFormat returns the format to use when reading the cell
func (*Field) GetReadIgnore ¶ added in v0.4.0
GetReadIgnore returns whether the field should be ignored when reading the cell
func (*Field) GetReadRequired ¶ added in v0.4.0
GetReadRequired returns whether the field is required when reading the cell
func (*Field) GetReadSplit ¶ added in v0.4.0
GetReadSplit returns the split to use when reading the cell
func (*Field) GetWriteColumnName ¶ added in v0.4.0
GetWriteColumnName returns the column name to write to the excel file
func (*Field) GetWriteDefault ¶ added in v0.4.0
func (f *Field) GetWriteDefault() interface{}
GetWriteDefault returns the default value to use if the cell is empty
func (*Field) GetWriteEncoding ¶ added in v0.4.0
GetWriteEncoding returns the encoding to use when writing the cell
func (*Field) GetWriteFormat ¶ added in v0.4.0
GetWriteFormat returns the format to use when writing the cell
func (*Field) GetWriteIgnore ¶ added in v0.4.0
GetWriteIgnore returns whether the field should be ignored when writing the cell
func (*Field) GetWriteRequired ¶ added in v0.4.0
GetWriteRequired returns whether the field is required when writing the cell
func (*Field) GetWriteSplit ¶ added in v0.4.0
GetWriteSplit returns the split to use when writing the cell
type Fields ¶ added in v0.4.0
type Fields []*Field
Fields is a list of Field
func (*Fields) CountReadIgnored ¶ added in v0.4.0
CountReadIgnored returns the number of ignored fields
func (*Fields) CountWriteIgnored ¶ added in v0.4.0
CountWriteIgnored returns the number of ignored fields
type IReadTags ¶ added in v0.4.0
The IReadTags interface can be used as a replacement of the mainTags parameters when importing an Excel file.
GetTagsIn is used when importing an Excel file and will be used if ITags is not implemented.
type ITags ¶ added in v0.4.0
The ITags interface can be used as a replacement of the mainTags parameters. The GetTags method must return a map of the mainTags. The key of the map is the name of the field and the value is a Tags structure.
Example:
type MyStruct struct {
Column1 string `excel:"column=MyColumn1"`
Column2 string `excel:"column=MyColumn2;required"`
Column3 string `excel:"column=MyColumn3;default=Hello World"`
}
func (s *MyStruct) GetTags() map[string]excel.MainTags {
return map[string]excel.MainTags{
"Column1": excel.MainTags{column: "MyColumn1"},
"Column2": excel.MainTags{column: "MyColumn2", Required: true},
"Column3": excel.MainTags{column: "MyColumn3", Default: "Hello World"},
}
}
In this example: the Column1 field will be mapped to the "MyColumn1" column of the Excel file. The Column2 field will be mapped to the "MyColumn2" column of the Excel file and it will be required. The Column3 field will be mapped to the "MyColumn3" column of the Excel file and it will have a default value of "Hello World".
type IWriteTags ¶ added in v0.4.0
The IWriteTags interface can be used as a replacement of the mainTags parameters when exporting an Excel file.
GetTagsOut is used when exporting an Excel file and will be used if ITags is not implemented.
type MapWriter ¶ added in v0.4.0
type MapWriter struct {
Writer *Writer
// contains filtered or unexported fields
}
func (*MapWriter) SetColumnsTags ¶ added in v0.4.0
type Marshaller ¶
type Marshaller interface {
Marshall() (interface{}, error)
}
Marshaller can be implemented by any Value that has a Marshal method This converter is used to convert the Value to the desired representation
type SliceReader ¶ added in v0.4.0
type SliceReader struct {
Reader *Reader
// contains filtered or unexported fields
}
func (*SliceReader) SetColumnsTags ¶ added in v0.4.0
func (r *SliceReader) SetColumnsTags(_ map[string]*Tags)
func (*SliceReader) Unmarshall ¶ added in v0.4.0
func (r *SliceReader) Unmarshall() error
type SliceWriter ¶ added in v0.4.0
type SliceWriter struct {
Writer *Writer
// contains filtered or unexported fields
}
func (*SliceWriter) Marshall ¶ added in v0.4.0
func (w *SliceWriter) Marshall(data any) error
func (*SliceWriter) SetColumnsTags ¶ added in v0.4.0
func (w *SliceWriter) SetColumnsTags(_ map[string]*Tags)
type StructReader ¶ added in v0.4.0
type StructReader struct {
Reader *Reader
Struct *Struct
// contains filtered or unexported fields
}
StructReader is the Excel reader for a struct It implements the IReader interface
func (*StructReader) SetColumnsTags ¶ added in v0.4.0
func (r *StructReader) SetColumnsTags(tags map[string]*Tags)
func (*StructReader) Unmarshall ¶ added in v0.4.0
func (r *StructReader) Unmarshall() error
Unmarshall reads the excel file and fill the container
type StructWriter ¶ added in v0.4.0
type StructWriter struct {
Writer *Writer
Struct *Struct
// contains filtered or unexported fields
}
StructWriter is the Excel writer for a struct It implements the IWriter interface
func (*StructWriter) Marshall ¶ added in v0.4.0
func (w *StructWriter) Marshall(data any) error
Marshall writes the Excel file from the container
func (*StructWriter) SetColumnsTags ¶ added in v0.4.0
func (w *StructWriter) SetColumnsTags(tags map[string]*Tags)
type Tags ¶ added in v0.4.0
type Tags struct {
Column string
Default interface{}
Format string
Encoding string
Split string
Required bool
Ignore bool
// contains filtered or unexported fields
}
Tags is used to store the mainTags parameters of a field.
The mainTags parameters are defined in the struct definition and are prefixed by "excel" and are used to configure the import and export of an Excel file.
Example:
type MyStruct struct {
Column1 string `excel:"column=MyColumn1"`
Column2 string `excel:"column=MyColumn2;required"`
Column3 string `excel:"column=MyColumn3;default=Hello World"`
}
In this example: the Column1 field will be mapped to the "MyColumn1" column of the Excel file. The Column2 field will be mapped to the "MyColumn2" column of the Excel file and it will be required. The Column3 field will be mapped to the "MyColumn3" column of the Excel file and it will have a default value of "Hello World".
type Unmarshaller ¶
Unmarshaller can be implemented by any Value that has an Unmarshall method This converter is used to convert the Value to the desired representation