commonxl

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecimalToFraction

func DecimalToFraction(val float64, nn, nd int) (num, den int)

DecimalToFraction converts a floating point value into a fraction approximation with at most nn digits in the numerator and nd digits in the denominator.

func DecimalToWholeFraction

func DecimalToWholeFraction(val float64, nn, nd int) (whole, num, den int)

DecimalToWholeFraction converts a floating point value into a whole number and fraction approximation with at most nn digits in the numerator and nd digits in the denominator.

Types

type Cell

type Cell []interface{}

Cell represents a single cell value.

func NewCell

func NewCell(value interface{}) Cell

NewCell creates a new cell value from any builtin type.

func NewCellWithType

func NewCellWithType(value interface{}, t CellType, f *Formatter) Cell

NewCellWithType creates a new cell value with the given type, coercing as necessary.

func (Cell) Clone

func (c Cell) Clone() Cell

Clone returns the new copy of this Cell.

func (Cell) Equal

func (c Cell) Equal(other Cell) bool

func (Cell) FormatNo

func (c Cell) FormatNo() uint16

FormatNo returns the NumberFormat used for display.

func (Cell) Less

func (c Cell) Less(other Cell) bool

func (*Cell) SetFormatNumber

func (c *Cell) SetFormatNumber(f uint16)

SetFormatNumber changes the number format stored with the cell.

func (*Cell) SetURL

func (c *Cell) SetURL(link string)

SetURL adds a URL hyperlink to the cell.

func (Cell) Type

func (c Cell) Type() CellType

Type returns the CellType of the value.

func (Cell) URL

func (c Cell) URL() (*url.URL, bool)

URL returns the parsed URL when a cell contains a hyperlink.

func (Cell) Value

func (c Cell) Value() interface{}

Value returns the contents as a generic interface{}.

type CellType

type CellType uint16

CellType annotates the type of data extracted in the cell.

const (
	BlankCell CellType = iota
	IntegerCell
	FloatCell
	StringCell
	BooleanCell
	DateCell

	HyperlinkStringCell // internal type to separate URLs
	StaticCell          // placeholder, internal use only
)

CellType annotations for various cell value types.

func (CellType) String

func (c CellType) String() string

String returns a string description of the cell data type.

type FmtFunc

type FmtFunc func(*Formatter, interface{}) string

FmtFunc will format a value according to the designated style.

type Formatter

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

Formatter contains formatting methods common to Excel spreadsheets.

func (*Formatter) Add

func (x *Formatter) Add(fmtID uint16, formatCode string) error

Add a custom number format to the formatter.

func (*Formatter) Apply

func (x *Formatter) Apply(fmtID uint16, val interface{}) (string, bool)

Apply the specified number format to the value. Returns false when fmtID is unknown.

func (*Formatter) ConvertToDate

func (x *Formatter) ConvertToDate(val float64) time.Time

ConvertToDate converts a floating-point value using the Excel date serialization conventions.

func (*Formatter) Get

func (x *Formatter) Get(fmtID uint16) (FmtFunc, bool)

Get the number format func to use for formatting values, it returns false when fmtID is unknown.

func (*Formatter) Mode1904

func (x *Formatter) Mode1904(enabled bool)

Mode1904 indicates that dates start on Jan 1, 1904 this setting was used in early MacOS Excel applications.

type Sheet

type Sheet struct {
	Formatter *Formatter
	NumRows   int
	NumCols   int
	Rows      [][]Cell

	CurRow int
}

Sheet holds raw and rendered values for a spreadsheet.

func (*Sheet) Err

func (s *Sheet) Err() error

Err returns the last error that occured.

func (*Sheet) Formats

func (s *Sheet) Formats() []string

Formats extracts the format code for the current record into a list.

func (*Sheet) IsEmpty

func (s *Sheet) IsEmpty() bool

IsEmpty returns true if there are no data values.

func (*Sheet) Next

func (s *Sheet) Next() bool

Next advances to the next record of content. It MUST be called prior to any Scan().

func (*Sheet) Put

func (s *Sheet) Put(row, col int, value interface{}, fmtNum uint16)

Put the value at the cell location given.

func (*Sheet) Raw

func (s *Sheet) Raw() []Cell

Raw extracts the raw Cell interfaces underlying the current row.

func (*Sheet) Resize

func (s *Sheet) Resize(rows, cols int)

Resize the sheet for the number of rows and cols given. Newly added cells default to blank.

func (*Sheet) Scan

func (s *Sheet) Scan(args ...interface{}) error

Scan extracts values from the current record into the provided arguments Arguments must be pointers to one of 5 supported types:

bool, int64, float64, string, or time.Time

If invalid, returns ErrInvalidScanType

func (*Sheet) Set

func (s *Sheet) Set(row, col int, value interface{})

Set changes the value in an existing cell location. NB Currently only used for populating string results for formulas.

func (*Sheet) SetURL

func (s *Sheet) SetURL(row, col int, link string)

SetURL adds a hyperlink to an existing cell location.

func (*Sheet) Strings

func (s *Sheet) Strings() []string

Strings extracts values from the current record into a list of strings.

func (*Sheet) Types

func (s *Sheet) Types() []string

Types extracts the data types from the current record into a list. options: "boolean", "integer", "float", "string", "date", and special cases: "blank", "hyperlink" which are string types

Jump to

Keyboard shortcuts

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