internal

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCharset  = errors.New("xlsx: unknown charset")
	ErrInvalidFile     = errors.New("xlsx: invalid file")
	ErrInvalidTemplate = errors.New("xlsx: invalid template")
)

Errors.

View Source
var Charsets = make(map[string]func(io.Reader) io.Reader)

Charsets represents the charsets.

Functions

func CellIdx

func CellIdx(ref string) (ridx int, cidx int)

CellIdx returns the cell index by reference.

func CellRef

func CellRef(i, j int) string

CellRef returns the cell reference by index.

func CharsetReader

func CharsetReader(charset string, r io.Reader) (io.Reader, error)

CharsetReader represents the charset reader.

func ColIdx

func ColIdx(ref string) int

ColIdx returns the column index by reference.

func ColRef

func ColRef(j int) string

ColRef returns the column reference by index.

func RangeIdx

func RangeIdx(ref string) (ridx1, cidx1 int, ridx2, cidx2 int)

RangeIdx returns the range index by ref.

func RangeRef

func RangeRef(ridx1, cidx1 int, ridx2, cidx2 int) string

RangeRef returns the range ref by index.

func RowIdx

func RowIdx(ref string) int

RowIdx returns the row index by reference.

func RowRef

func RowRef(i int) string

RowRef returns the row reference by index.

Types

type Book

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

Book represents a book.

func LoadZIP

func LoadZIP(zr *zip.Reader) (*Book, error)

LoadZIP loads book from zip.Reader.

func (*Book) Clone

func (b *Book) Clone() *Book

Clone clones the book with no sheet data.

func (*Book) DumpZIP

func (b *Book) DumpZIP(zw *zip.Writer) error

DumpZIP dumps the book to zip.Writer.

func (*Book) MarshalXML

func (b *Book) MarshalXML(encoder *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

func (*Book) Sheets

func (b *Book) Sheets() []*Sheet

Sheets returns the sheets in the book.

func (*Book) UnmarshalXML

func (b *Book) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML decodes a single XML element beginning with the given start element.

type Cell

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

Cell represents a cell.

func (*Cell) Bool

func (c *Cell) Bool() bool

Bool returns the cell value as bool.

func (*Cell) Float

func (c *Cell) Float() float64

Float returns the cell value as float64.

func (*Cell) Int

func (c *Cell) Int() int

Int returns the cell value as int.

func (*Cell) IsBlank

func (c *Cell) IsBlank() bool

IsBlank returns whether it is a blank cell.

func (*Cell) MarshalXML

func (c *Cell) MarshalXML(encoder *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

func (*Cell) Primary

func (c *Cell) Primary() *Cell

Primary returns the primary cell. The returned cell is guaranteed not to be nil.

func (*Cell) SetBool

func (c *Cell) SetBool(v bool)

SetBool sets bool value to the cell.

func (*Cell) SetFloat

func (c *Cell) SetFloat(v float64)

SetFloat sets float64 value to the cell.

func (*Cell) SetInt

func (c *Cell) SetInt(v int)

SetInt sets int value to the cell.

func (*Cell) SetString

func (c *Cell) SetString(v string)

SetString sets string value to the cell.

func (*Cell) SetTime

func (c *Cell) SetTime(v time.Time)

SetTime sets time.Time value to the cell. Ignore time zone information.

func (*Cell) String

func (c *Cell) String() string

String returns the cell value as string.

func (*Cell) Time

func (c *Cell) Time() time.Time

Time returns the cell value as time.Time. Using UTC time zone.

func (*Cell) UnmarshalXML

func (c *Cell) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML decodes a single XML element beginning with the given start element.

type ComplexFragment

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

ComplexFragment represents a complex fragment of a template.

func (*ComplexFragment) Clone

func (cf *ComplexFragment) Clone(ctx map[*Cell]*Cell) Fragment

Clone clones the fragment.

func (*ComplexFragment) Fill

func (cf *ComplexFragment) Fill(sheet *Sheet, level int, data reflect.Value) error

Fill applies a parsed fragment to the specified data, and writes the output to the sheet.

func (*ComplexFragment) Key

func (cf *ComplexFragment) Key(level int) string

Key returns the key of the fragment.

type ContentTypes

type ContentTypes struct {
	XMLName   xml.Name
	Defaults  []*Element `xml:"Default,omitempty"`
	Overrides []Override `xml:"Override,omitempty"`
}

ContentTypes represents the content types.

func (*ContentTypes) Add

func (c *ContentTypes) Add(pname string, ctype string)

Add adds a override to content types.

type Dimension

type Dimension struct {
	Ref string `xml:"ref,attr"`
}

Dimension represents a dimension element.

type Element

type Element struct {
	Attrs    []xml.Attr `xml:",any,attr,omitempty"`
	InnerXML []byte     `xml:",innerxml"`
}

Element represents a xml element.

type Entry

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

Entry represents a book entry.

func (*Entry) Decode

func (e *Entry) Decode(v any, replace bool) error

Decode decodes the entry to v.

func (*Entry) Encode

func (e *Entry) Encode(name string, zw *zip.Writer) error

Encode encodes the entry to zip.Writer by name.

type Fragment

type Fragment interface {
	// Key returns the key of the fragment.
	Key(level int) string

	// Clone clones the fragment.
	Clone(ctx map[*Cell]*Cell) Fragment

	// Fill applies a parsed fragment to the specified data, and writes the output to the sheet.
	Fill(sheet *Sheet, level int, data reflect.Value) error
}

Fragment represents a fragment of a template.

func BuildFragment

func BuildFragment(sheet *Sheet) (Fragment, error)

BuildFragment build fragment from sheet.

type MergeCell

type MergeCell struct {
	Ref string `xml:"ref,attr"`
}

MergeCell represents a mergeCell element.

type MergeCells

type MergeCells struct {
	Count   int          `xml:"count,attr"`
	Entries []*MergeCell `xml:"mergeCell,omitempty"`
}

MergeCells represents the mergeCell elements.

type Override

type Override struct {
	PartName    string `xml:"PartName,attr"`
	ContentType string `xml:"ContentType,attr"`
}

Override represents the content override.

type Rel

type Rel struct {
	ID     string `xml:"Id,attr"`
	Type   string `xml:"Type,attr"`
	Target string `xml:"Target,attr"`
}

Rel represents a rel.

type Rels

type Rels struct {
	XMLName xml.Name
	Entries []Rel `xml:"Relationship"`
}

Rels represents a rels.

func (*Rels) Add

func (r *Rels) Add(rtype, target string)

Add adds a new rel to rels.

func (*Rels) Find

func (r *Rels) Find(rtype string) string

Find finds the target by type.

func (*Rels) Get

func (r *Rels) Get(id string) string

Get gets the target by id.

type Row

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

Row represents a row.

func (*Row) Cells

func (r *Row) Cells() []*Cell

Cells returns the cells in the row.

func (*Row) ICell

func (r *Row) ICell(cidx int) *Cell

ICell returns the cell by index.

func (*Row) IsBlank

func (r *Row) IsBlank() bool

IsBlank returns whether it is a blank row.

func (*Row) MarshalXML

func (r *Row) MarshalXML(encoder *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

func (*Row) UnmarshalXML

func (r *Row) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML decodes a single XML element beginning with the given start element.

type SSI

type SSI struct {
	Text Text  `xml:"t,omitempty"`
	SSRs []SSR `xml:"r,omitempty"`
}

SSI represents a shared string si element.

func (*SSI) IsRich

func (ssi *SSI) IsRich() bool

IsRich returns whether the ssi is rich text or not.

func (*SSI) String

func (ssi *SSI) String() string

String returns the ssi text.

type SSR

type SSR struct {
	Pr   *Element `xml:"rPr,omitempty"`
	Text Text     `xml:"t"`
}

SSR represents a shared string r element.

type SST

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

SST represents the shared strings.

func (*SST) Get

func (sst *SST) Get(i string) *SSI

Get returns the ssi by index.

func (*SST) MarshalXML

func (sst *SST) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

func (*SST) Put

func (sst *SST) Put(s string) string

Put puts the string into the sst and returns the index.

func (*SST) Reset

func (sst *SST) Reset()

Reset resets the sst.

func (*SST) UnmarshalXML

func (sst *SST) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML decodes a single XML element beginning with the given start element.

type Sheet

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

Sheet represents a sheet.

func (*Sheet) Fill

func (s *Sheet) Fill()

Fill sheet with template values.

func (*Sheet) IRow

func (s *Sheet) IRow(ridx int) *Row

IRow returns the row by index.

func (*Sheet) MarshalXML

func (s *Sheet) MarshalXML(encoder *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

func (*Sheet) Name

func (s *Sheet) Name() string

Name returns the sheet name.

func (*Sheet) Rows

func (s *Sheet) Rows() []*Row

Rows return the rows in the sheet.

func (*Sheet) UnmarshalXML

func (s *Sheet) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

UnmarshalXML decodes a single XML element beginning with the given start element.

type SheetInfo

type SheetInfo struct {
	Attrs []xml.Attr `xml:",any,attr,omitempty"`
	ID    xml.Attr   `xml:"id,attr"`
	Name  string     `xml:"name,attr"`
}

SheetInfo represents the sheet infomation.

type SimpleFragment

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

SimpleFragment represents a simple fragment of a template.

func (*SimpleFragment) Clone

func (sf *SimpleFragment) Clone(ctx map[*Cell]*Cell) Fragment

Clone clones the fragment.

func (*SimpleFragment) Fill

func (sf *SimpleFragment) Fill(sheet *Sheet, level int, data reflect.Value) (err error)

Fill applies a parsed fragment to the specified data, and writes the output to the sheet.

func (*SimpleFragment) Key

func (sf *SimpleFragment) Key(level int) string

Key returns the key of the fragment.

type Text

type Text string

Text represents a text element.

func (Text) MarshalXML

func (a Text) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

Jump to

Keyboard shortcuts

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