Documentation
¶
Index ¶
- Variables
- type Axis
- type Container
- type Excel
- func (e *Excel) AddTable(table *Table) error
- func (e *Excel) DeleteTable(name string) error
- func (e *Excel) DeleteTableContent(name string) error
- func (e *Excel) GetActiveSheet() *Sheet
- func (e *Excel) GetSheet(name string) *Sheet
- func (e *Excel) GetSheetFromIndex(index int) *Sheet
- func (e *Excel) GetTable(name string) (*Table, error)
- func (e *Excel) GetTableSheet(name string) (*Sheet, error)
- func (e *Excel) GetTables() ([]Table, error)
- func (e *Excel) Marshal(container any, tags ...map[string]*Tags) error
- func (e *Excel) ResizeTable(table *Table, newRange string) error
- func (e *Excel) SetActiveSheet(sheet *Sheet)
- func (e *Excel) SetAxis(axis string)
- func (e *Excel) SetAxisCoordinates(col int, row int)
- func (e *Excel) SetSheet(sheet *Sheet)
- func (e *Excel) SetSheetFromIndex(index int)
- func (e *Excel) SetSheetFromName(name string)
- func (e *Excel) Sheet() *Sheet
- 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 Range
- func (r *Range) AddColumns(columns int) error
- func (r *Range) AddRows(rows int) error
- func (r *Range) ColumnAsRange(column int) (*Range, error)
- func (r *Range) Columns() int
- func (r *Range) FirstColumnAsRange() (*Range, error)
- func (r *Range) FirstRowAsRange() (*Range, error)
- func (r *Range) LastColumnAsRange() (*Range, error)
- func (r *Range) LastRowAsRange() (*Range, error)
- func (r *Range) RemoveColumns(columns int) error
- func (r *Range) RemoveRows(rows int) error
- func (r *Range) RowAsRange(row int) (*Range, error)
- func (r *Range) Rows() int
- func (r *Range) SetColumns(columns int) error
- func (r *Range) SetRows(rows int) error
- func (r *Range) ToRef() string
- func (r *Range) UpdateNames() error
- type Reader
- type ReaderResult
- type Sheet
- type SliceReader
- type SliceWriter
- type Struct
- type StructReader
- type StructWriter
- type Table
- func (t *Table) Delete() error
- func (t *Table) DeleteContent() error
- func (t *Table) GetColumn(title string) (int, error)
- func (t *Table) GetColumnAt(index int) (string, error)
- func (t *Table) GetDataRange() (*Range, error)
- func (t *Table) GetHeaderRange() (*Range, error)
- func (t *Table) GetRange() (*Range, error)
- func (t *Table) IsValid() bool
- func (t *Table) IsValidError() error
- func (t *Table) Resize(newRange string) error
- type Tags
- type Unmarshaller
- type Writer
- type WriterResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrFileIsNil = errors.New("excel: the file is nil") ErrAxisNotValid = errors.New("excel: the axis is not valid") ErrConfigNotValid = errors.New("excel: the configuration is not valid") ErrSheetNotValid = errors.New("excel: the sheet name is not valid") ErrSheetNotFound = errors.New("excel: the sheet is not found") ErrSheetNameEmpty = errors.New("excel: the sheet name is empty") ErrSheetIndex = errors.New("excel: the sheet index is not valid") ErrTableNameEmpty = errors.New("excel: the table name is empty") ErrTableRange = errors.New("excel: the table range 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) DeleteTable ¶ added in v0.6.0
DeleteTable deletes the table in the Excel file
func (*Excel) DeleteTableContent ¶ added in v0.6.0
DeleteTableContent deletes the content of the table in the Excel file
func (*Excel) GetActiveSheet ¶ added in v0.6.0
GetActiveSheet returns the active sheet
func (*Excel) GetSheetFromIndex ¶ added in v0.6.0
GetSheetFromIndex returns the sheet object
func (*Excel) GetTableSheet ¶ added in v0.6.0
GetTableSheet returns the sheet where the table is located
func (*Excel) ResizeTable ¶ added in v0.6.0
ResizeTable resize the table by changing the range
func (*Excel) SetActiveSheet ¶ added in v0.6.0
SetActiveSheet sets the active sheet
func (*Excel) SetAxisCoordinates ¶
SetAxisCoordinates sets the axis coordinates to be used by the reader or writer
func (*Excel) SetSheetFromIndex ¶ added in v0.6.0
SetSheetFromIndex sets the sheet index to be used by the reader or writer
func (*Excel) SetSheetFromName ¶ added in v0.6.0
SetSheetFromName 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 IReader ¶ added in v0.4.0
type IReader interface {
Unmarshall() (*ReaderResult, error)
SetColumnsTags(tags map[string]*Tags)
}
IReader interface All readers must implement this interface
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 IWriter ¶ added in v0.4.0
type IWriter interface {
Marshall(data any) (*WriterResult, error)
SetColumnsTags(tags map[string]*Tags)
}
IWriter interface All writers must implement this interface
type MapWriter ¶ added in v0.4.0
type MapWriter struct {
Writer *Writer
// contains filtered or unexported fields
}
func (*MapWriter) Marshall ¶ added in v0.4.0
func (w *MapWriter) Marshall(data any) (*WriterResult, error)
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 Range ¶ added in v0.6.0
type Range struct {
// StartColumn is the start column of the range
StartColumn int
// StartRow is the start row of the range
StartRow int
// StartName is the start name of the range
StartName string
// EndColumn is the end column of the range
EndColumn int
// EndRow is the end row of the range
EndRow int
// EndName is the end name of the range
EndName string
}
Range represent the range in the Excel file where data will read or write
func (*Range) AddColumns ¶ added in v0.6.0
AddColumns adds columns to the range
func (*Range) ColumnAsRange ¶ added in v0.6.0
ColumnAsRange returns the range of the column
func (*Range) FirstColumnAsRange ¶ added in v0.6.0
FirstColumnAsRange returns the range of the first column
func (*Range) FirstRowAsRange ¶ added in v0.6.0
FirstRowAsRange returns the range of the first row
func (*Range) LastColumnAsRange ¶ added in v0.6.0
LastColumnAsRange returns the range of the last column
func (*Range) LastRowAsRange ¶ added in v0.6.0
LastRowAsRange returns the range of the last row
func (*Range) RemoveColumns ¶ added in v0.6.0
RemoveColumns removes columns from the range
func (*Range) RemoveRows ¶ added in v0.6.0
RemoveRows removes rows from the range
func (*Range) RowAsRange ¶ added in v0.6.0
RowAsRange returns the range of the row
func (*Range) SetColumns ¶ added in v0.6.0
SetColumns sets the number of columns in the range
func (*Range) UpdateNames ¶ added in v0.6.0
UpdateNames updates the name of the range
type Reader ¶
type Reader struct {
Sheet Sheet
Axis Axis
Result *ReaderResult
// contains filtered or unexported fields
}
Reader is the Excel reader
type ReaderResult ¶ added in v0.5.0
ReaderResult is a struct that contains the result of the reader
type Sheet ¶
Sheet represent the sheet in the Excel file where data will read or write
func (*Sheet) GetComment ¶ added in v0.6.0
GetComment returns the comment of the cell
func (*Sheet) IsValidError ¶ added in v0.6.0
IsValidError returns an error if the sheet is not valid
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() (*ReaderResult, 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) (*WriterResult, 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() (*ReaderResult, 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) (*WriterResult, 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 Table ¶ added in v0.6.0
Table represent the table in the Excel file
func (*Table) DeleteContent ¶ added in v0.6.0
DeleteContent deletes the content of the table
func (*Table) GetColumnAt ¶ added in v0.6.0
GetColumnAt returns the column name at the desired index
func (*Table) GetDataRange ¶ added in v0.6.0
GetDataRange returns the range of the data of the table
func (*Table) GetHeaderRange ¶ added in v0.6.0
GetHeaderRange returns the range of the header of the table
func (*Table) IsValidError ¶ added in v0.6.0
IsValidError returns an error if the table is not valid
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
type Writer ¶
type Writer struct {
Sheet Sheet
Axis Axis
Result *WriterResult
// contains filtered or unexported fields
}
Writer is the Excel writer
type WriterResult ¶ added in v0.5.0
WriterResult is a struct that contains the result of the writer