Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( //DirectionHorizontal = "horizontal" //DirectionVertical vertial direction DirectionVertical = "vertical" )
View Source
const TagName = "xls"
Variables ¶
This section is empty.
Functions ¶
func ParseStyle ¶
Types ¶
type Column ¶
type Column struct {
Position int
Name string
Tag *Tag
Field *xunsafe.Field
Table *Table
// contains filtered or unexported fields
}
ColumnAddress represents acolumn
func (*Column) CellStyleID ¶
CellStyleID returns a style ID
func (*Column) ColumnStyleID ¶
ColumnStyleID returns column style ID or nil
func (*Column) HeaderStyleID ¶
HeaderStyleID returns header style ID or nil
type Marshaller ¶
type Marshaller struct {
// contains filtered or unexported fields
}
Marshaller represents xls marshalle
func NewMarshaller ¶
func NewMarshaller(opts ...Option) *Marshaller
NewMarshaller create a marshaler with option
Example ¶
package main
import (
"bytes"
"context"
"github.com/viant/afs"
"github.com/viant/afs/file"
"github.com/viant/xlsy"
"log"
"time"
)
func main() {
now := time.Now().Truncate(time.Second)
type Record struct {
ID int `xls:"name=ID"`
Name string `xls:"name=Name"`
Active bool `xls:"name=Active,style={color:blue}"`
Started *time.Time `xls:"name=Started,style={width:200px;format:date}"`
}
var records = []*Record{
{
ID: 1,
Name: "Item 1",
Active: true,
Started: &now,
},
{
ID: 2,
Name: "Item 2",
Active: false,
Started: &now,
},
{
ID: 3,
Name: "Item 3",
Active: true,
Started: &now,
},
}
marshaller := xlsy.NewMarshaller(xlsy.WithDefaultStyle("font-style:bold"))
data, err := marshaller.Marshal(records)
if err != nil {
log.Fatal(err)
}
fs := afs.New()
err = fs.Upload(context.Background(), "test.xlsx", file.DefaultFileOsMode, bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
}
Output:
func (*Marshaller) Marshal ¶
func (m *Marshaller) Marshal(any interface{}) ([]byte, error)
Marshal marshall arbitrary type to xls
type Option ¶
type Option func(m *session) error
Option represents marshaller session
func WithDefaultHeaderStyle ¶
func WithDefaultStyle ¶
func WithNamedStyles ¶
WithNamedStyles accept name/style definition pairs
type Style ¶
type Style struct {
Destination string //default cell,
ID string
Definition string
Header *extStyle
Cell *extStyle
Column *extStyle
}
Style represents a style
type StyleTag ¶
func (*StyleTag) Definition ¶
type Stylizer ¶
type Stylizer struct {
// contains filtered or unexported fields
}
Stylizer represents stylizer
type Table ¶
type Table struct {
Parent *Column
Stylizer *Stylizer
*Tag
Columns Columns
Header *Row
Rows Rows
Type reflect.Type
IsStruct bool
Cardinality int
// contains filtered or unexported fields
}
Table represents a table
func (*Table) IsStandalone ¶
Click to show internal directories.
Click to hide internal directories.