xlsx

package module
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: 11 Imported by: 0

README

XLSX

Go Reference

Package xlsx implements a simple xlsx library.

Feature

  • Easily read/write spreadsheets.
  • Easily load data from spreadsheets.
  • Easily fill data into spreadsheets.

Dependencies

  • go 1.20+

Usage

import "gitee.com/erdian718/xlsx"

func main() {
	book, err := xlsx.LoadFile("path_to_load.xlsx")
	if err != nil {
		panic(err)
	}

	// ...

	if err := book.DumpFile("path_to_dump.xlsx"); err != nil {
		panic(err)
	}
}

Note

  • Only support xlsx format.

Documentation

Overview

Package xlsx implements a simple xlsx library.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCharset     = internal.ErrUnknownCharset
	ErrInvalidFile        = internal.ErrInvalidFile
	ErrInvalidTemplate    = internal.ErrInvalidTemplate
	ErrInvalidQueryOption = errors.New("xlsx: invalid query option")
)

Errors.

Functions

func Register

func Register(charset string, decoder func(io.Reader) io.Reader)

Register registers a charset decoder.

Types

type Book

type Book internal.Book

Book represents a workbook.

func LoadBytes

func LoadBytes(bs []byte) (*Book, error)

LoadBytes loads book from bytes.

func LoadFile

func LoadFile(name string) (*Book, error)

LoadFile loads book from file.

func LoadReader

func LoadReader(r io.Reader) (*Book, error)

LoadReader loads book from io.Reader.

func (*Book) DumpBytes

func (b *Book) DumpBytes() ([]byte, error)

DumpBytes dumps the book to bytes.

func (*Book) DumpFile

func (b *Book) DumpFile(name string) error

DumpFile dumps the book to file.

func (*Book) DumpWriter

func (b *Book) DumpWriter(w io.Writer) error

DumpWriter dumps the book to io.Writer.

func (*Book) Sheet

func (b *Book) Sheet(name string) *Sheet

Sheet returns the sheet by name. If name is empty, return the first sheet. If there is no sheet corresponding to the name, return nil.

func (*Book) Sheets

func (b *Book) Sheets(yield func(*Sheet) bool)

Sheets represents the sheets sequence. The sheets are guaranteed not to be nil.

type Cell

type Cell internal.Cell

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) 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.

type QueryOptions

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

QueryOptions represents the query options.

func NewQueryOptions

func NewQueryOptions() *QueryOptions

NewQueryOptions returns a default query options. Default:

Head: 1
SkipBlank: true

func (*QueryOptions) Head

func (opts *QueryOptions) Head(option int) *QueryOptions

Head marks the number of rows for head.

func (*QueryOptions) SkipBlank

func (opts *QueryOptions) SkipBlank(option bool) *QueryOptions

SkipBlank marks whether to skip blank rows.

func (*QueryOptions) SkipBottom

func (opts *QueryOptions) SkipBottom(option int) *QueryOptions

SkipBottom marks the number of rows skipped at the bottom.

func (*QueryOptions) SkipLeft

func (opts *QueryOptions) SkipLeft(option int) *QueryOptions

SkipLeft marks the number of rows skipped at the left.

func (*QueryOptions) SkipRight

func (opts *QueryOptions) SkipRight(option int) *QueryOptions

SkipRight marks the number of rows skipped at the right.

func (*QueryOptions) SkipTop

func (opts *QueryOptions) SkipTop(option int) *QueryOptions

SkipTop marks the number of rows skipped at the top.

type Record

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

Record represents a record.

func (Record) Bool

func (r Record) Bool(keys ...string) bool

Bool returns bool value by keys.

func (Record) Float

func (r Record) Float(keys ...string) float64

Float returns float value by keys.

func (Record) Int

func (r Record) Int(keys ...string) int

Int returns int value by keys.

func (Record) String

func (r Record) String(keys ...string) string

String returns string value by keys.

func (Record) Time

func (r Record) Time(keys ...string) time.Time

Time returns time.Time value by keys.

type Row

type Row internal.Row

Row represents a row.

func (*Row) Cell

func (r *Row) Cell(ref string) *Cell

Cell returns the cell by reference. The returned cell is guaranteed not to be nil.

func (*Row) Cells

func (r *Row) Cells(yield func(*Cell) bool)

Cells represents the cells sequence. The cells are guaranteed not to be nil.

func (*Row) ICell

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

ICell returns the cell by index. The returned cell is guaranteed not to be nil.

func (*Row) IsBlank

func (r *Row) IsBlank() bool

IsBlank returns whether it is a blank row.

func (*Row) Len

func (r *Row) Len() int

Len return the length of cells.

type Sheet

type Sheet internal.Sheet

Sheet represents a worksheet.

func (*Sheet) Cell

func (s *Sheet) Cell(ref string) *Cell

Cell returns the cell by reference. The returned cell is guaranteed not to be nil.

func (*Sheet) ICell

func (s *Sheet) ICell(ridx, cidx int) *Cell

ICell returns the cell by index. The returned cell is guaranteed not to be nil.

func (*Sheet) IRow

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

IRow returns the row by index. The returned row is guaranteed not to be nil.

func (*Sheet) Len

func (s *Sheet) Len() int

Len return the length of rows.

func (*Sheet) Name

func (s *Sheet) Name() string

Name returns the sheet name.

func (*Sheet) Query

func (s *Sheet) Query(options *QueryOptions) func(func(Record) bool)

Query queries the records. If options is nil, use the default options.

func (*Sheet) Row

func (s *Sheet) Row(ref string) *Row

Row returns the row by reference. The returned row is guaranteed not to be nil.

func (*Sheet) Rows

func (s *Sheet) Rows(yield func(*Row) bool)

Rows represents the rows sequence. The rows are guaranteed not to be nil.

type Template

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

Template is the representation of a parsed template. It is goroutine safe.

func ParseBytes

func ParseBytes(bs []byte) (*Template, error)

ParseBytes creates a new Template and parses the template definitions from the bytes.

func ParseFile

func ParseFile(name string) (*Template, error)

ParseFiles creates a new Template and parses the template definitions from the named file.

func ParseReader

func ParseReader(r io.Reader) (*Template, error)

ParseReader creates a new Template and parses the template definitions from the Reader.

func (*Template) ExecuteBytes

func (t *Template) ExecuteBytes(data any) ([]byte, error)

ExecuteBytes applies a parsed template to the specified data object, and writes the output to the bytes.

func (*Template) ExecuteFile

func (t *Template) ExecuteFile(name string, data any) error

ExecuteFile applies a parsed template to the specified data object, and writes the output to the named file.

func (*Template) ExecuteWriter

func (t *Template) ExecuteWriter(w io.Writer, data any) error

ExecuteWriter applies a parsed template to the specified data object, and writes the output to the Writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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