Documentation
¶
Index ¶
- Constants
- func FromExcelTime(n float64) time.Time
- func ParseBool(s string) (bool, error)
- func ParseTime(s string) (time.Time, error)
- func ToExcelTime(tm time.Time) float64
- type BoolValue
- type CellRangeReference
- type CellReference
- type Constant
- type DataSet
- type Dimensions
- type Error
- type ErrorValue
- type Expression
- type Float64Value
- type Formula
- type FunctionCall
- type InvalidPosError
- type NameError
- type NamedRangeReference
- type NotAvailableError
- type Operator
- type Pos
- type Range
- type Sheet
- type StringValue
- type TimeValue
- type Value
- type ValueError
- type ValueIter
- type ValueRange
Constants ¶
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 ¶
FromExcelTime converts an Excel fractional datetime to the appropriate golang time.Time.
func ParseBool ¶
ParseBool parses one of the recognized boolean strings (a subset of the boolean strings recognized by golang).
func ToExcelTime ¶
ToExcelTime converts a golang time.Time to the Excel fractional date equivalent.
Types ¶
type CellRangeReference ¶
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 ¶
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 Dimensions ¶
type Dimensions struct {
EndRow, EndCol int
}
Dimensions are the dimensions of a sheet.
type Error ¶
Error is a sheet-specific error.
var ErrDivideByZero Error = ÷ByZeroError{}
ErrDivideByZero occurs when a number if divided by 0.
func NameErrorf ¶
NameErrorf returns a NameError with a formnatted message.
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 ¶
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 ¶
A Formula resolves / transforms values from a DataSet.
func ParseFormula ¶
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 ¶
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
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
type Pos ¶
type Pos struct {
Row, Col int
}
Pos is the position of a cell in a sheet. Uses 0-based indexing.
type Range ¶
A Range is a description of a collection of cells in a sheet. Uses 0-based indexing.
func ParseRange ¶
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) ContainsRange ¶
ContainsRange returns true if this range contains another 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 ¶
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 Value ¶
type Value interface { ToFloat64() (float64, error) fmt.Stringer // contains filtered or unexported methods }
Value is a cell value.
func StringToValue ¶
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 ¶
SingleValueIter wraps a single Value in an iterator.
func SliceValueIter ¶
SliceValueIter wraps a slice of Values in an iterator.
type ValueRange ¶
A ValueRange is an iterator that can report its position in the sheet