sheets

package
v0.0.0-...-800124d Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxRow is used as the value of EndRow to indicate that the range
	// covers up to the maximum row in the sheet.
	MaxRow = -1

	// MaxColumn is used as the value of EndColumn to indicate that the range
	// covers up to the maximum column in the sheet.
	MaxColumn = -1
)

Variables

This section is empty.

Functions

func FromExcelTime

func FromExcelTime(n float64) time.Time

FromExcelTime converts an Excel fractional datetime to the appropriate golang time.Time.

func ParseBool

func ParseBool(s string) (bool, error)

ParseBool parses one of the recognized boolean strings (a subset of the boolean strings recognized by golang).

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime parses a string as a time, using the support date and time formats.

func ToExcelTime

func ToExcelTime(tm time.Time) float64

ToExcelTime converts a golang time.Time to the Excel fractional date equivalent.

Types

type BoolValue

type BoolValue bool

Various types of values.

func (BoolValue) String

func (v BoolValue) String() string

func (BoolValue) ToFloat64

func (v BoolValue) ToFloat64() (float64, error)

ToFloat64 converts the value to a float64.

type CellRangeReference

type CellRangeReference struct {
	Sheet string
	Range Range
}

A CellRangeReference is a reference to a range of cells in a sheet.

func (*CellRangeReference) String

func (r *CellRangeReference) String() string

String returns the string form of the reference.

type CellReference

type CellReference struct {
	Sheet string
	Pos   Pos
}

A CellReference is a reference to a cell in a sheet.

func (*CellReference) String

func (r *CellReference) String() string

String returns the string form of the reference.

type Constant

type Constant struct {
	Value Value
}

A Constant is a constant value.

func (*Constant) String

func (c *Constant) String() string

String returns the constant in string format.

type DataSet

type DataSet interface {
	Sheet(name string) Sheet
}

A DataSet is a set of sheets, functions, and named ranges.

type Dimensions

type Dimensions struct {
	EndRow, EndCol int
}

Dimensions are the dimensions of a sheet.

type Error

type Error interface {
	Error() string
	TypeName() string
}

Error is a sheet-specific error.

var ErrDivideByZero Error = &divideByZeroError{}

ErrDivideByZero occurs when a number if divided by 0.

func NameErrorf

func NameErrorf(msg string, args ...any) Error

NameErrorf returns a NameError with a formnatted message.

func UnwrapError

func UnwrapError(err error) (Error, bool)

UnwrapError unwraps a sheet error.

type ErrorValue

type ErrorValue struct {
	Err error
}

ErrorValue is a value that is an error.

func (ErrorValue) String

func (v ErrorValue) String() string

func (ErrorValue) ToFloat64

func (v ErrorValue) ToFloat64() (float64, error)

ToFloat64 converts the value to a float64.

type Expression

type Expression struct {
	Left, Right Formula
	Operator    Operator
}

An Expression applies an operator to the results of two formula.

func (*Expression) String

func (expr *Expression) String() string

String returns the Expression in string form.

type Float64Value

type Float64Value float64

Various types of values.

func (Float64Value) String

func (v Float64Value) String() string

func (Float64Value) ToFloat64

func (v Float64Value) ToFloat64() (float64, error)

ToFloat64 converts the value to a float64.

type Formula

type Formula interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

A Formula resolves / transforms values from a DataSet.

func ParseFormula

func ParseFormula(s string) (Formula, error)

ParseFormula parses a formula.

Formulas don't really follow a context-free grammar, but a pseudo-EBNF looks something like:

Formula := <Expression> { ">" | "<" | ">=" | "<=" | "<>" <Expression> } Expression := <Term> { ("+" | "-") <Term> }* Term := <Factor> { ("*"|"/") <Expression>}* Factor := <FunctionCall> | <Reference> | <Constant> | "(" <Formula> ")" FunctionCall := IDENTIFIER '(' <ArgList>? ')' ArgList := <Formula> (',' <Formula>)* Reference := <Sheet>? (CELL | CELL_RANGE | NAMED_RANGE) Constant := STRING | NUMBER | TRUE | FALSE STRING = QuotedString TRUE = [Tt][Rr][Uu][Ee] FALSE = [Ff][Aa][Ll][Ss][Ee] IDENTIFIER = [A-Aa-z_][A-Za-z0-9_]* CELL = ([A-Za-z]+)(0-9+) CELL_RANGE = ([A-Za-z]+)?([0-9]+)?\s*:\s*([A-Za-z]+)?([0-9]+)?

type FunctionCall

type FunctionCall struct {
	FunctionName string
	Args         []Formula
}

A FunctionCall is a call of a function with a set of arguments.

func (*FunctionCall) String

func (fc *FunctionCall) String() string

String returns the function call in string form.

type InvalidPosError

type InvalidPosError struct {
	Pos Pos
}

InvalidPosError is returned when attempting to access a position outside the bounds of a sheet.

func (InvalidPosError) Error

func (e InvalidPosError) Error() string

Error returns the error message.

type NameError

type NameError struct {
	Message string
}

A NameError occurs when a formula or function is unable to find the data it needs to complete a calculation. This can happen for a number of reasons, including:

  • A typo in the formula name
  • The formula refers to a name that has not been defined
  • The formula has a typo in the defined name
  • The syntax is missing double quotation marks for text values
  • A colon was omitted in a range reference

func (*NameError) Error

func (e *NameError) Error() string

func (*NameError) TypeName

func (e *NameError) TypeName() string

type NamedRangeReference

type NamedRangeReference struct {
	NamedRange string
}

A NamedRangeReference is a reference to a named range.

func (*NamedRangeReference) String

func (r *NamedRangeReference) String() string

String returns the named range reference.

type NotAvailableError

type NotAvailableError struct {
	Message string
}

NotAvailableError means "no value is available."

func NotAvailableErrorf

func NotAvailableErrorf(msg string, args ...any) *NotAvailableError

NotAvailableErrorf creates a new NotAvailableError with a formatted message.

func (NotAvailableError) Error

func (e NotAvailableError) Error() string

func (NotAvailableError) TypeName

func (e NotAvailableError) TypeName() string

type Operator

type Operator string

An Operator is a comparison or arithmetic operator in an expression

const (
	Add      Operator = "+"
	Subtract Operator = "-"
	Multiply Operator = "*"
	Divide   Operator = "/"
	Exp      Operator = "^"
	Gt       Operator = ">"
	Lt       Operator = "<"
	Geq      Operator = ">="
	Leq      Operator = "<="
	Eq       Operator = "="
	Neq      Operator = "<>"
)

Various Operators

func (Operator) Apply

func (op Operator) Apply(v1, v2 Value) Value

Apply applies the operator to two values, returning the results of the operator.

type Pos

type Pos struct {
	Row, Col int
}

Pos is the position of a cell in a sheet. Uses 0-based indexing.

func ParsePos

func ParsePos(s string) (Pos, error)

ParsePos parses a position in the form "AA23" where "AA" is the column and 23 is the row in 1-based indexing.

func (Pos) String

func (pos Pos) String() string

String returns the string form of a Pos.

type Range

type Range struct {
	StartRow, EndRow int
	StartCol, EndCol int
}

A Range is a description of a collection of cells in a sheet. Uses 0-based indexing.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses a range in the form "AA23:BC45" where "AA23" is the starting position of the range and "BC45" is the ending position of the range. Supports four formats:

* AA23:BC54 - covers all cells in columns AA-BC and rows 23-54 * AA:CBC - covers all rows in columns AA-BC * 23:54 - covers rows 23-54 in every column

func (Range) Contains

func (r Range) Contains(pos Pos) bool

Contains returns true if the range contains the given position.

func (Range) ContainsRange

func (r Range) ContainsRange(other Range) bool

ContainsRange returns true if this range contains another range.

func (Range) EndPos

func (r Range) EndPos() Pos

EndPos returns the end position of the range

func (Range) NextPos

func (r Range) NextPos(pos Pos) (nextPos Pos, insideRange bool)

NextPos advances the given position within the range.

func (Range) NumCells

func (r Range) NumCells() int

NumCells returns the number of cells covered by the range.

func (Range) StartPos

func (r Range) StartPos() Pos

StartPos returns the start position of the range

func (Range) String

func (r Range) String() string

String returns the string form of the range

type Sheet

type Sheet interface {
	Get(ctx context.Context, pos Pos) (Value, error)
	Range(ctx context.Context, r Range) (ValueRange, error)
	Dimensions() Dimensions
}

A Sheet is allows arbitrary access to a matrix of cells.

func NewInMemorySheet

func NewInMemorySheet(values [][]Value) (Sheet, error)

NewInMemorySheet creates a sheet that wraps a two-dimensional matrix.

type StringValue

type StringValue string

Various types of values.

func (StringValue) String

func (v StringValue) String() string

func (StringValue) ToFloat64

func (v StringValue) ToFloat64() (float64, error)

ToFloat64 converts the value to a float64.

type TimeValue

type TimeValue time.Time

Various types of values.

func (TimeValue) String

func (v TimeValue) String() string

func (TimeValue) ToFloat64

func (v TimeValue) ToFloat64() (float64, error)

ToFloat64 converts the value to a float64.

type Value

type Value interface {
	ToFloat64() (float64, error)
	fmt.Stringer
	// contains filtered or unexported methods
}

Value is a cell value.

func StringToValue

func StringToValue(s string) Value

StringToValue converts a string into a Value, using the most optimal Value representation.

type ValueError

type ValueError struct {
	Message string
}

A ValueError occurs when a formula contains cells with different data types, or when a formula references cells that contain text instead of numbers. The #VALUE! error can also occur when:

  • A cell reference refers to an error value
  • The function's syntax is incorrect
  • IF statements are built in a complex way
  • A cell contains a space character
  • Cells contain hidden or non-printing characters
  • Formula references a few ranges that are not of the same size or shape

func ValueErrorf

func ValueErrorf(msg string, args ...any) *ValueError

ValueErrorf creates a new ValueError with a formatted message.

func (ValueError) Error

func (e ValueError) Error() string

func (ValueError) TypeName

func (e ValueError) TypeName() string

type ValueIter

type ValueIter interface {
	Next(ctx context.Context) bool
	Err() error
	Value() Value
	Index() int
	Len() int
}

A ValueIter is an iterator over a set of values.

func SingleValueIter

func SingleValueIter(val Value) ValueIter

SingleValueIter wraps a single Value in an iterator.

func SliceValueIter

func SliceValueIter(vals []Value) ValueIter

SliceValueIter wraps a slice of Values in an iterator.

type ValueRange

type ValueRange interface {
	ValueIter
	Pos() Pos
}

A ValueRange is an iterator that can report its position in the sheet

Directories

Path Synopsis
internal
formula
Package formula are internal helpers for dealing with formula.
Package formula are internal helpers for dealing with formula.

Jump to

Keyboard shortcuts

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