Documentation
¶
Overview ¶
Package formula parses, prints and evaluates the spreadsheet formulas lfm builds: the portable subset Excel 2019+, Google Sheets and LibreOffice all compute the same way. Placeholders in square brackets ([Log.amount], [.amount], [income]) name columns and cells by meaning; a resolver turns them into references for one edition, so a sheet can be renamed per language without touching a formula.
Index ¶
- Constants
- func CellName(col, row int) string
- func ColumnName(n int) string
- func ColumnNumber(letters string) int
- func Date(serial float64) time.Time
- func Definable(name string) bool
- func Functions() []string
- func Print(n Node) string
- func PrintAt(n Node, row int) string
- func QuoteSheet(name string) string
- func Serial(t time.Time) float64
- type Area
- type AreaBook
- type Binary
- type Book
- type Bool
- type Call
- type Context
- type Err
- type Kind
- type Node
- type Num
- type Ref
- type Resolver
- type Run
- type Str
- type Unary
- type Value
Constants ¶
const ( ErrDiv0 = "#DIV/0!" ErrNA = "#N/A" ErrValue = "#VALUE!" ErrRef = "#REF!" ErrName = "#NAME?" ErrNum = "#NUM!" )
The error values.
Variables ¶
This section is empty.
Functions ¶
func ColumnNumber ¶
ColumnNumber turns A into 1 and AA into 27.
func Definable ¶
Definable reports whether a name can be an Excel defined name: not a cell address (tax1 is column TAX, row 1), not R1C1 notation, not a logical value or a function's name. Google Sheets and LibreOffice accept the same names.
func Print ¶
Print writes n in the syntax xlsx files store: English function names with the prefixes newer functions need, commas between arguments, a dot as the decimal mark and quoted sheet names. Every app shows the formula in its own language from this.
func QuoteSheet ¶
QuoteSheet quotes a sheet name for a reference: 'Mein Budget'!A1.
Types ¶
type AreaBook ¶
type AreaBook interface {
Book
Area(sheet string, c1, r1, c2, r2 int) (rows [][]Value, cells *Run)
}
AreaBook is a Book that reads whole areas itself, such as one that memoizes them; the rows it returns are never modified.
type Book ¶
Book gives the evaluator the cells of a workbook. A cell holding a formula returns its evaluated value; the book evaluates it on demand.
type Context ¶
type Context struct {
Book Book
Sheet string // the sheet of the cell, for references without a sheet
Row int // the row of the cell, for Here references
Today time.Time
// Volatile is set when the formula reads TODAY(): its value changes
// with the day it is computed.
Volatile *bool
// Unportable receives what the formula did that the apps compute
// differently, such as joining TRUE into text.
Unportable func(string)
}
Context is where a formula is evaluated.
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is a parsed formula.
type Ref ¶
type Ref struct {
Sheet string
Col, Row int
AbsCol, AbsRow bool
Here bool
Name string // a defined name the file stores instead of the address
}
Ref is one cell; Col and Row count from 1. A Here reference is in the row of the cell the formula belongs to: one parsed formula serves every row of a table column.
type Run ¶
type Run struct {
Values []Value
// contains filtered or unexported fields
}
Run is an area's cells in reading order. Its index of texts, which lets SUMIFS and the other *IFS functions find the rows equal to a text without scanning, is built on first use.
type Value ¶
type Value struct {
Kind Kind
Num float64
Str string // text, or the error code
Rows [][]Value
// contains filtered or unexported fields
}
Value is the result of a formula or the content of a cell.