Documentation
¶
Overview ¶
Package sheet is the spreadsheet engine: cell storage, formula parsing and dependency-ordered recalculation. It has no knowledge of the terminal UI.
Index ¶
- Constants
- Variables
- func CleanNote(text string) string
- func ColName(c int) string
- func FormatNumber(v float64, width int) string
- func FormatPattern(v float64, pat string) string
- func FormatText(v Value, f Format) string
- func FormatValue(v Value, width int) string
- func IsFormulaEntry(input string) bool
- func IsPending(v Value) bool
- func MaxCells() int
- func ParseCol(s string) (int, bool)
- func ParseNumber(s string) (float64, bool)
- func Qualified(sheet string, r Rect) string
- func QuoteSheet(name string) string
- func RangesText(rs []Rect) string
- func SetMaxCells(n int)
- func ShiftEntry(input string, dc, dr int) (string, error)
- func SplitSheet(s string) (sheet, rest string)
- func ValidMacroName(name string) error
- func ValidName(name string) error
- func ValidSheetName(name string) error
- type Addr
- type Align
- type Cell
- type Change
- type Chart
- type ChartData
- type ChartFate
- type ChartLegend
- type ChartOptions
- type ChartSeries
- type ChartStack
- type ChartType
- type Clip
- type Color
- type CondFormat
- type CondOp
- type Condition
- type Criteria
- type Filter
- type FilterValue
- type FindOptions
- type Format
- type FormatKind
- type FuncDef
- type ImportResult
- type InvalidEntry
- type Kind
- type Look
- type Macro
- type Name
- type Node
- type ParseError
- type Pivot
- type PivotFilter
- type PivotGroup
- type PivotInfo
- type PivotValue
- type PointKind
- type Protection
- type RecalcInfo
- type Rect
- type RemoteAnswer
- type RemoteCall
- type RemoteSource
- type RuleOp
- type RuleStyle
- type ScalePoint
- type Sheet
- func (s *Sheet) AddChart(c Chart) int
- func (s *Sheet) AddCondFormat(f CondFormat) error
- func (s *Sheet) AddValidation(v Validation) error
- func (s *Sheet) Addrs() []Addr
- func (s *Sheet) AdjustDecimals(r Rect, delta int)
- func (s *Sheet) Batch(c Change, fn func() error) error
- func (s *Sheet) Book() *Workbook
- func (s *Sheet) CanRedo() bool
- func (s *Sheet) CanUndo() bool
- func (s *Sheet) Cell(a Addr) *Cell
- func (s *Sheet) CellFormat(a Addr) Format
- func (s *Sheet) CellStyle(a Addr) Style
- func (s *Sheet) ChartData(c Chart) ChartData
- func (s *Sheet) Charts() []Chart
- func (s *Sheet) CheckEntry(a Addr, input string) *InvalidEntry
- func (s *Sheet) ClearCondFormats(cr Rect)
- func (s *Sheet) ClearFormatting(r Rect)
- func (s *Sheet) ClearHistory()
- func (s *Sheet) ClearNotes(r Rect) int
- func (s *Sheet) ClearValidations(cr Rect)
- func (s *Sheet) ColFormats() map[int]Format
- func (s *Sheet) ColStyles() map[int]Style
- func (s *Sheet) ColWidth(c int) int
- func (s *Sheet) ColumnFiltered(col int) bool
- func (s *Sheet) CondFormats() []CondFormat
- func (s *Sheet) Copy(r Rect) *Clip
- func (s *Sheet) CreateFilter(r Rect)
- func (s *Sheet) Decimal() bool
- func (s *Sheet) DefineName(name string, r Rect) error
- func (s *Sheet) DeleteChart(i int)
- func (s *Sheet) DeleteCols(at, n int)
- func (s *Sheet) DeleteCondFormat(i int)
- func (s *Sheet) DeleteName(name string) error
- func (s *Sheet) DeleteRows(at, n int)
- func (s *Sheet) DeleteValidation(i int)
- func (s *Sheet) Dependents(a Addr) []Target
- func (s *Sheet) DisplayFormat(a Addr) Format
- func (s *Sheet) DropdownItems(a Addr) []string
- func (s *Sheet) Edge(a Addr, dc, dr int) Addr
- func (s *Sheet) EditName(old, name string, r Rect) error
- func (s *Sheet) EraseRange(r Rect)
- func (s *Sheet) ExplainError(a Addr) string
- func (s *Sheet) FillDown(r Rect) (Rect, error)
- func (s *Sheet) FillEntry(r Rect, origin Addr, input string) error
- func (s *Sheet) FillRight(r Rect) (Rect, error)
- func (s *Sheet) FillSeries(src, dst Rect) (Rect, error)
- func (s *Sheet) FilledBounds(r Rect) (Rect, bool)
- func (s *Sheet) Filter() *Filter
- func (s *Sheet) FilterColumn(col int, cr Criteria)
- func (s *Sheet) FilterRange() (Rect, bool)
- func (s *Sheet) FilterValues(col int) []FilterValue
- func (s *Sheet) Find(query string, o FindOptions) ([]Addr, error)
- func (s *Sheet) Frozen() (rows, cols int)
- func (s *Sheet) GuessChart(r Rect) Chart
- func (s *Sheet) HasRules() bool
- func (s *Sheet) HasSpills() bool
- func (s *Sheet) Hidden() bool
- func (s *Sheet) HiddenRows() int
- func (s *Sheet) InPivot(r Rect) bool
- func (s *Sheet) InSpill(r Rect) (Addr, bool)
- func (s *Sheet) InsertCols(at, n int) error
- func (s *Sheet) InsertRows(at, n int) error
- func (s *Sheet) Len() int
- func (s *Sheet) Link(a Addr) string
- func (s *Sheet) Live() bool
- func (s *Sheet) Load(a Addr, input string, f Format, st Style) error
- func (s *Sheet) LoadColWidth(c, w int)
- func (s *Sheet) LoadCondFormats(fs []CondFormat) (skipped int)
- func (s *Sheet) LoadFilter(f *Filter)
- func (s *Sheet) LoadFrozen(rows, cols int)
- func (s *Sheet) LoadLineFormat(row bool, n int, f Format, st Style)
- func (s *Sheet) LoadNote(a Addr, text string)
- func (s *Sheet) LoadProtection(p Protection)
- func (s *Sheet) LoadValidations(vs []Validation) (skipped int)
- func (s *Sheet) Look(a Addr) Look
- func (s *Sheet) LookupName(name string) (Name, bool)
- func (s *Sheet) Move(src Rect, to Addr) (Rect, error)
- func (s *Sheet) MoveCondFormat(i, to int)
- func (s *Sheet) MoveTo(dst *Sheet, src Rect, to Addr) (Rect, error)
- func (s *Sheet) Name() string
- func (s *Sheet) NameUsers(name string) int
- func (s *Sheet) NamedSheets(a Addr) []string
- func (s *Sheet) Names() []Name
- func (s *Sheet) NextFilledCol(row, col, dir, limit int) (int, bool)
- func (s *Sheet) NextShownRow(r, d int) (int, bool)
- func (s *Sheet) Note(a Addr) string
- func (s *Sheet) NotesIn(r Rect) []Addr
- func (s *Sheet) Paste(c *Clip, dst Rect, values bool) (Rect, error)
- func (s *Sheet) Pivot() (Pivot, bool)
- func (s *Sheet) PivotError() string
- func (s *Sheet) PivotRange() (Rect, bool)
- func (s *Sheet) PivotSource() *Sheet
- func (s *Sheet) Precedents(a Addr) []Target
- func (s *Sheet) Protect(p Protection)
- func (s *Sheet) Protecting(r Rect) (Protection, bool)
- func (s *Sheet) Protections() []Protection
- func (s *Sheet) RangeStats(r Rect) Stats
- func (s *Sheet) RecalcAll()
- func (s *Sheet) RecalcVolatile()
- func (s *Sheet) Redo() (Change, bool)
- func (s *Sheet) Region(a Addr) Rect
- func (s *Sheet) RemoteCalls(a Addr) []RemoteCall
- func (s *Sheet) RemoveFilter()
- func (s *Sheet) Replace(a Addr, query, repl string, o FindOptions) (bool, error)
- func (s *Sheet) ReplaceAll(query, repl string, o FindOptions) (int, error)
- func (s *Sheet) RowFormats() map[int]Format
- func (s *Sheet) RowHidden(r int) bool
- func (s *Sheet) RowStyles() map[int]Style
- func (s *Sheet) Seal()
- func (s *Sheet) Set(a Addr, input string) error
- func (s *Sheet) SetChart(i int, c Chart, label string)
- func (s *Sheet) SetColWidth(c, w int)
- func (s *Sheet) SetCondFormat(i int, f CondFormat) error
- func (s *Sheet) SetDecimal(on bool)
- func (s *Sheet) SetFormat(r Rect, f Format)
- func (s *Sheet) SetFrozen(rows, cols int)
- func (s *Sheet) SetNote(a Addr, text string) error
- func (s *Sheet) SetPivot(p Pivot, label string) error
- func (s *Sheet) SetRemote(r RemoteSource)
- func (s *Sheet) SetStyle(r Rect, fn func(*Style))
- func (s *Sheet) SetValidation(i int, v Validation) error
- func (s *Sheet) SheetFormat() (Format, Style)
- func (s *Sheet) ShownText(a Addr) string
- func (s *Sheet) SortRange(r Rect, keys []SortKey)
- func (s *Sheet) SpillAnchor(a Addr) (Addr, bool)
- func (s *Sheet) SpillArea(a Addr) (Rect, bool)
- func (s *Sheet) StateID() int
- func (s *Sheet) Undo() (Change, bool)
- func (s *Sheet) Unload(a Addr)
- func (s *Sheet) Unprotect(i int)
- func (s *Sheet) UnprotectRange(r Rect) int
- func (s *Sheet) UsedRange() (Rect, bool)
- func (s *Sheet) Validation(a Addr) (Validation, bool)
- func (s *Sheet) Validations() []Validation
- func (s *Sheet) Value(a Addr) Value
- func (s *Sheet) Widths() map[int]int
- func (s *Sheet) Write(w io.Writer) error
- type ShowAs
- type SortKey
- type Stats
- type Style
- type Summarize
- type Target
- type ValidKind
- type Validation
- type Value
- type Workbook
- func (w *Workbook) Active() int
- func (w *Workbook) AddSheet(name string, at int) (*Sheet, error)
- func (w *Workbook) Batch(c Change, fn func() error) error
- func (w *Workbook) Begin(c Change) (end func())
- func (w *Workbook) CanRedo() bool
- func (w *Workbook) CanUndo() bool
- func (w *Workbook) ClearHistory()
- func (w *Workbook) CreatePivot(src *Sheet, r Rect, name string, p Pivot) (*Sheet, error)
- func (w *Workbook) Decimal() bool
- func (w *Workbook) DefaultSummarize(p Pivot, col int) Summarize
- func (w *Workbook) DefineName(name string, s *Sheet, r Rect) error
- func (w *Workbook) DeleteMacro(name string) bool
- func (w *Workbook) DeleteName(name string) error
- func (w *Workbook) DeleteSheet(s *Sheet) error
- func (w *Workbook) DuplicateSheet(s *Sheet) (*Sheet, error)
- func (w *Workbook) EditName(old, name string, s *Sheet, r Rect) error
- func (w *Workbook) FieldName(p Pivot, col int) string
- func (w *Workbook) HiddenSheets() []*Sheet
- func (w *Workbook) HideSheet(s *Sheet) error
- func (w *Workbook) HistoryBytes() int64
- func (w *Workbook) Index(s *Sheet) int
- func (w *Workbook) InsertBook(src *Workbook, at int, label string) (ImportResult, error)
- func (w *Workbook) Len() int
- func (w *Workbook) Lookup(name string) *Sheet
- func (w *Workbook) LookupName(name string) (Name, bool)
- func (w *Workbook) Macro(name string) (Macro, bool)
- func (w *Workbook) MacroForKey(key string) (Macro, bool)
- func (w *Workbook) MacroOrigin() string
- func (w *Workbook) Macros() []Macro
- func (w *Workbook) MoveSheet(s *Sheet, to int)
- func (w *Workbook) NameUsers(name string) int
- func (w *Workbook) Names() []Name
- func (w *Workbook) NextPivotName() string
- func (w *Workbook) PivotFilterValues(p Pivot, col int) []FilterValue
- func (w *Workbook) RecalcAll()
- func (w *Workbook) RecalcAnswered(calls []RemoteCall)
- func (w *Workbook) Redo() (Change, bool)
- func (w *Workbook) RenameSheet(s *Sheet, name string) error
- func (w *Workbook) ReplaceSheet(dst, s *Sheet, label string) ([]ChartFate, error)
- func (w *Workbook) SaveMacro(old string, mc Macro, label string) error
- func (w *Workbook) Seal()
- func (w *Workbook) SetActive(s *Sheet)
- func (w *Workbook) SetDecimal(on bool)
- func (w *Workbook) SetMacroOrigin(origin string)
- func (w *Workbook) SetRemote(r RemoteSource)
- func (w *Workbook) SetTrace(trace any)
- func (w *Workbook) Settle()
- func (w *Workbook) Sheet(i int) *Sheet
- func (w *Workbook) Sheets() []*Sheet
- func (w *Workbook) StateID() int
- func (w *Workbook) Undo() (Change, bool)
- func (w *Workbook) UndoLabel() string
- func (w *Workbook) UnhideSheet(s *Sheet) error
- func (w *Workbook) ValueTitle(p Pivot, v PivotValue) string
- func (w *Workbook) Visible() []*Sheet
- func (w *Workbook) Write(out io.Writer) error
Constants ¶
const (
MinChartW, MinChartH = 20, 8
MaxChartW, MaxChartH = 240, 120
)
Chart size limits, in terminal cells.
const ( MaxCols = formula.MaxCols MaxRows = formula.MaxRows )
Worksheet bounds, matching Lotus 1-2-3 Release 2 (A..IV, 1..8192).
const ( Empty = value.Empty Number = value.Number Text = value.Text Bool = value.Bool Error = value.Error )
Kinds of values.
const ( FmtAuto = value.FmtAuto FmtText = value.FmtText FmtNumber = value.FmtNumber FmtPercent = value.FmtPercent FmtScientific = value.FmtScientific FmtAccounting = value.FmtAccounting FmtFinancial = value.FmtFinancial FmtCurrency = value.FmtCurrency FmtDate = value.FmtDate FmtTime = value.FmtTime FmtDateTime = value.FmtDateTime FmtDuration = value.FmtDuration FmtCustom = value.FmtCustom // MaxDecimals caps Increase decimal places. MaxDecimals = value.MaxDecimals )
Number formats.
const DefaultMaxCells = 2_000_000
DefaultMaxCells is the max-cells setting's default: about 600 MB of cells at 300 bytes each.
const DefaultWidth = 10
DefaultWidth is the initial column width: nine characters plus padding.
const FileExt = ".012"
FileExt is the extension of the native worksheet format.
const MacroAPI = 1
MacroAPI is the version of the scripting API macros are written for. A file records it with each macro, so a later build that changes the API can tell old scripts from new ones.
const MaxFrozen = 50
MaxFrozen caps frozen rows and columns, as Sheets' View > Freeze does in practice: more than a screenful can't stay on screen anyway.
const MaxNote = 4096
MaxNote caps a note's length in bytes, so a file or a paste can't make one without bound.
const MaxUndo = 100
MaxUndo is how many steps of undo history a workbook keeps, at most; MaxUndoBytes also bounds it.
const MaxUndoBytes = 256 << 20
MaxUndoBytes caps the memory the undo history's before-images hold, as estimated by step.size. When a new step takes the history past it, the oldest steps are dropped first; the newest step is always kept, however large, so any single change can be undone. 256 MB keeps MaxUndo steps that each rewrite a whole column (about 250 MB, see docs/contributing/limits.md).
const NumColors = int(numColors)
NumColors is how many colors there are, ColorNone included, for tables indexed by Color.
Variables ¶
var ( // OnBegin, when set, is called as a recalculation ("recalc") or a // pivot table refresh ("pivot") begins; OnRecalc or OnPivot as it // ends. They pair up like parentheses: a recalculation holds the // pivot refreshes it causes, which follow its own evaluation. OnBegin func(trace any, op string) // OnRecalc, when set, is called after every recalculation of any // workbook. OnRecalc func(trace any, i RecalcInfo) )
The engine knows nothing of logging; cmd/012 points these hooks at telemetry. They run on the goroutine that changed the workbook and must be cheap. trace is the workbook's (see SetTrace), handed back so the engine's work is timed as spans nested in whatever the workbook's owner has open: a command, an import, a macro run.
var ( ErrPushedOff = errors.New("There's data at the edge of the sheet that would be pushed off") ErrPasteEdge = errors.New("The paste doesn't fit: it would go past the edge of the sheet") ErrFillTooBig = errors.New("That would write more cells than max-cells allows (see File > Settings)") )
Errors returned by operations that would lose data or don't fit.
var ( // Pending is shown while an answer is on its way. Pending = functions.Pending // ErrNoRemote means JEV functions can't run: there is no API key. ErrNoRemote = functions.ErrNoRemote // ErrRemote is a question the model couldn't answer. ErrRemote = functions.ErrRemote )
var ( ErrDiv0 = value.ErrDiv0 ErrValue = value.ErrValue ErrName = value.ErrName ErrNA = value.ErrNA ErrNum = value.ErrNum ErrRef = value.ErrRef // also circular references )
Error values, using Google Sheets codes.
var ChartTypes = func() []ChartType { out := make([]ChartType, len(chartTypeNames)) for i := range out { out[i] = ChartType(i) } return out }()
ChartTypes lists the types in the order the chart editor offers them.
var ( // ErrPivotEdit is what editing a pivot table's results says, as // Sheets refuses to. ErrPivotEdit = errors.New("Pivot table results can't be edited: change the pivot with Data > Edit pivot table") )
Errors of pivot tables.
var ErrSpillEdit = errors.New("That cell holds part of an array result: edit the formula it spills from")
ErrSpillEdit is what typing into a spilled cell says: its value belongs to the formula that spilled it.
var OnPivot func(trace any, i PivotInfo)
OnPivot, when set, is called after every pivot recomputation, like OnRecalc (see OnBegin).
Functions ¶
func CleanNote ¶ added in v0.2.0
CleanNote tidies a note as SetNote stores it: control characters other than line breaks dropped, trailing space trimmed, at most MaxNote bytes.
func FormatNumber ¶
FormatNumber formats a number in the General format within width columns, for use outside the grid (e.g. the status line).
func FormatPattern ¶
FormatPattern renders v with a number format pattern, as TEXT() does.
func FormatText ¶
FormatText renders v under f with no width limit, e.g. for TEXT() or copying out of the grid.
func FormatValue ¶
FormatValue renders v in width columns with one column of padding, the way the grid shows it in Automatic format: numbers right-aligned, booleans and errors centered. Text is not handled here because it can overflow into neighboring cells.
func IsFormulaEntry ¶
IsFormulaEntry reports whether input is written as a formula: it starts with "=", or with "+" or "-" followed by something that isn't a plain number (as Sheets accepts "+A1").
func ParseNumber ¶
ParseNumber recognizes numbers the way Google Sheets does on entry.
func QuoteSheet ¶
QuoteSheet writes a sheet name as a formula needs it, e.g. 'Q3 plan'.
func RangesText ¶ added in v0.2.0
RangesText writes ranges as ParseRanges reads them.
func SetMaxCells ¶
func SetMaxCells(n int)
SetMaxCells sets the cell budget; n < 1 restores the default.
func ShiftEntry ¶
ShiftEntry returns an entry as if it were typed in one cell and copied dc columns and dr rows away: a formula's relative references move and $absolute ones stay, as in a paste. Other entries come back unchanged. A macro recorded with relative references replays formulas this way.
func SplitSheet ¶
SplitSheet splits a reference such as "'Q3 plan'!B2" into the sheet name, unquoted, and the rest.
func ValidMacroName ¶
ValidMacroName reports why name can't name a macro, or nil.
func ValidName ¶
ValidName checks that name can be a named range, following Sheets' rules: letters, digits, _ and ., starting with a letter or _, and not something a formula would read as a cell or a boolean.
func ValidSheetName ¶
ValidSheetName checks a name for a sheet, following Excel's rules (a superset of what Sheets accepts is fine to read, but names written by 012 must open in Excel too).
Types ¶
type Align ¶
type Align uint8
Align is a cell's horizontal alignment.
func Display ¶
Display renders v under format f for a cell width columns wide, as the grid shows it: the text without padding, and where it goes. Numbers go right, text left, booleans and errors center. A formatted number that doesn't fit in width-1 columns becomes a run of #, as in Sheets; Automatic first drops decimals and falls back to scientific notation. Accounting returns AlignFill: exactly width columns, $ at the left.
func ParseAlign ¶
ParseAlign is the inverse of Align.String.
type Cell ¶
type Cell struct {
// Input is the entry exactly as typed: text, a number such as "$1,200"
// or "12%", or a formula starting with "=". Empty for a blank cell
// that only has formatting.
Input string
Value Value
// Format and Style are plain values, so copying a Cell copies its
// formatting. They survive clearing the contents, as in Sheets.
Format Format
Style Style
// Note is the cell's note, as Sheets' Insert > Note: text shown when
// the cell is active or hovered. Like formatting, it survives clearing
// the contents, and it moves and copies with the cell.
Note string
// contains filtered or unexported fields
}
Cell holds what the user typed, what it evaluates to, and how it is formatted. A cell may have formatting but no contents (Sheets lets you format blank cells before typing); such a cell counts as blank everywhere contents matter.
type Change ¶
type Change struct {
Label string
Focus Rect
Sheet *Sheet
// Tabs is set when the step added, deleted, renamed or moved sheets;
// Focus means nothing then.
Tabs bool
// Macros is set when the step changed nothing but the macros; Focus
// means nothing then either.
Macros bool
}
Change describes an undo step: what it did, in lower case for use in a sentence ("clear B3:B5"), the sheet it happened on and the range it affected there.
type Chart ¶
type Chart struct {
Type ChartType
Data Rect
// ByRow puts each series in a row instead of a column, like Sheets'
// "Switch rows / columns".
ByRow bool
// Header takes series names from the first row of the data (the first
// column when ByRow).
Header bool
// Labels takes category labels from the first column of the data (the
// first row when ByRow).
Labels bool
Title string
At Addr // the cell under the top-left corner
W, H int // size in terminal cells
// ChartOptions are the stacking, axis and legend settings of Sheets'
// Customize tab; see chartopts.go.
ChartOptions
}
Chart is a chart floating over the grid.
type ChartData ¶
type ChartData struct {
Categories []string
Series []ChartSeries
Format Format
}
ChartData is what a chart draws: category labels and series of the same length, and the number format of the values, for axis labels.
type ChartFate ¶
type ChartFate struct {
Name string // the chart's title, or Chart 1, Chart 2 by position
Was, Now Rect // the range it drew, and draws
// Removed is set when the range no longer fits the new data: it
// holds nothing now, or it was a whole table and the new sheet's
// table there has other series.
Removed bool
}
ChartFate says what replacing a sheet did to one of its charts.
type ChartLegend ¶ added in v0.2.0
type ChartLegend int
ChartLegend is where a chart's legend goes.
const ( LegendBottom ChartLegend = iota // under the plot, centered LegendRight // a column right of the plot LegendNone // no legend )
func ParseChartLegend ¶ added in v0.2.0
func ParseChartLegend(s string) (ChartLegend, bool)
ParseChartLegend parses a position as String writes it.
func (ChartLegend) String ¶ added in v0.2.0
func (l ChartLegend) String() string
String is the position as files store it.
type ChartOptions ¶ added in v0.2.0
type ChartOptions struct {
// Stack stacks the series of column, bar and area charts.
Stack ChartStack
// Trend draws a linear trend line through each series of a scatter
// chart.
Trend bool
// Min and Max fix the ends of the value axis when HasMin and HasMax
// are set; otherwise the axis fits the data.
Min, Max float64
HasMin, HasMax bool
// Log puts the value axis on a logarithmic scale, leaving out values
// that aren't positive.
Log bool
// NoGrid hides the gridlines.
NoGrid bool
// Legend is where the legend goes.
Legend ChartLegend
}
ChartOptions are a chart's settings beyond its type and data, as in the Customize tab of Sheets' chart editor. The zero value is Sheets' default: not stacked, no trend line, an automatic linear value axis with gridlines, and the legend at the bottom. Every field is a plain value, so charts stay comparable with ==.
type ChartSeries ¶
ChartSeries is one named run of values. Blank and non-numeric cells are NaN, drawn as gaps.
type ChartStack ¶ added in v0.2.0
type ChartStack int
ChartStack is how the series of a chart pile up.
const ( StackNone ChartStack = iota // side by side StackNormal // on top of each other StackPercent // on top of each other, as shares of 100% )
func ParseChartStack ¶ added in v0.2.0
func ParseChartStack(s string) (ChartStack, bool)
ParseChartStack parses a stacking as String writes it.
func (ChartStack) String ¶ added in v0.2.0
func (s ChartStack) String() string
String is the stacking as files store it, "" for none.
func (ChartStack) Title ¶ added in v0.2.0
func (s ChartStack) Title() string
Title is the stacking as the chart editor shows it.
type ChartType ¶
type ChartType int
ChartType is how a chart draws its series. Adding one takes a constant here and its name in chartTypeNames; the chart editor, the file format and ChartTypes follow from the table, and internal/chart draws it.
func ParseChartType ¶
ParseChartType parses a type name as String writes it.
type Clip ¶
type Clip struct {
Range Rect // the range copied
Src Rect // Range trimmed to its cells when whole lines
// contains filtered or unexported fields
}
Clip is a copied range: snapshots of its cells, and of the formatting they show, taken at copy time.
func (*Clip) MoveRange ¶
MoveRange is the range cutting c moves when pasted at to: the whole lines copied when to starts a line, else the copied cells.
func (*Clip) Text ¶
Text returns the clip's values as displayed in General format, row by row, for the system clipboard. Blank rows and columns past the last value are left off, so copying whole columns gives their data; a block of more than MaxCells cells, blanks between values included, is too big for text, and Text returns nil.
type Color ¶ added in v0.2.0
type Color uint8
Color is one of the named colors rules draw with. Each is an ANSI color slot, so the terminal's palette or the color scheme applies: the UI maps them to theme roles, never to fixed RGB.
func Colors ¶ added in v0.2.0
func Colors() []Color
Colors lists the named colors, ColorNone first, in the order the rules editor offers them.
func ParseColor ¶ added in v0.2.0
ParseColor is the inverse of Color.String, ignoring case.
type CondFormat ¶ added in v0.2.0
type CondFormat struct {
Ranges []Rect
// Op is the test of a single-color rule and Args its values, as
// typed: "100", "=B2" (a formula, relative to the first range's
// top-left cell as a copied formula would be), a date, or for
// RuleFormula the formula, e.g. "=$C2>100".
Op RuleOp
Args [2]string
Style RuleStyle
// Scale, when set, makes the rule a color scale of 2 or 3 points,
// lowest first, and Op, Args and Style mean nothing.
Scale []ScalePoint
}
CondFormat is a conditional format rule.
func ParseCondFormat ¶ added in v0.2.0
func ParseCondFormat(line string) (CondFormat, error)
ParseCondFormat reads a rule written by JSON, checking it.
func (CondFormat) Check ¶ added in v0.2.0
func (f CondFormat) Check() error
Check reports why a rule can't be used, in words for the rules editor.
func (CondFormat) IsScale ¶ added in v0.2.0
func (f CondFormat) IsScale() bool
IsScale reports whether the rule is a color scale.
func (CondFormat) JSON ¶ added in v0.2.0
func (f CondFormat) JSON() string
JSON writes the rule as a line of the file, e.g. {"ranges":"B2:B20","condition":"gt","values":["100"],"fill":"green"}.
func (CondFormat) Summary ¶ added in v0.2.0
func (f CondFormat) Summary() string
Summary describes the rule in a few words, e.g. "Greater than 100".
type CondOp ¶
type CondOp uint8
CondOp is one of Sheets' filter conditions.
func CondOps ¶
func CondOps() []CondOp
CondOps lists the conditions in the order Sheets' menu shows them.
func ParseCondOp ¶
ParseCondOp is the inverse of CondOp.String.
type Condition ¶
type Condition struct {
Op CondOp
Arg string // the value compared with, as typed; unused by CondEmpty and CondNotEmpty
}
Condition is a test on a cell, e.g. "greater than 100".
type Criteria ¶
Criteria is what one column of a filter lets through: its displayed value must not be one of Hidden (Sheets' "Filter by values", unchecked values; "" stands for blanks) and must meet Cond ("Filter by condition").
type Filter ¶
type Filter struct {
Range Rect
Cols map[int]Criteria // by column; a column without criteria hides nothing
}
A filter hides the rows of a range whose values don't meet criteria set per column, as Sheets' Data > Create a filter. Rows are hidden, never deleted: formulas still see them (SUM over a filtered range includes hidden rows, as in Sheets). The range's first row holds the headers and is never hidden. Criteria are re-applied whenever values change.
type FilterValue ¶
FilterValue is one entry of a filter's values list: a value as shown, how many rows have it, and whether it is checked (shown).
type FindOptions ¶
type FindOptions struct {
MatchCase bool
WholeCell bool // the whole cell must match, not just part of it
Regex bool // the query is a regular expression; replacements may use $1
InFormulas bool // search formula text instead of formula results
Within *Rect // limit the search to a range; nil searches the sheet
}
FindOptions mirror Google Sheets' Find and replace dialog.
type Format ¶
Format is a cell's number format.
func ParseValue ¶
ParseValue recognizes everything Sheets turns into a number on entry: numbers, currency, percentages, dates and times, with the format Sheets applies.
func Preset ¶
func Preset(k FormatKind) Format
Preset returns kind with Sheets' default decimals: two for the number kinds.
type FormatKind ¶
type FormatKind = value.FormatKind
FormatKind is a number format from Sheets' Format > Number menu.
func ParseFormatKind ¶
func ParseFormatKind(s string) (FormatKind, bool)
ParseFormatKind is the inverse of FormatKind.String.
type FuncDef ¶
FuncDef describes a spreadsheet function.
func LookupFunc ¶
LookupFunc finds a function by name or alias; callers pass upper case.
type ImportResult ¶
type ImportResult struct {
Sheets []*Sheet // the sheets added, in tab order
Renamed map[string]string // imported names changed to fit, old to new
Names int // named ranges left out, their names taken
}
ImportResult says what an import into a workbook did.
type InvalidEntry ¶ added in v0.2.0
type InvalidEntry struct {
Addr Addr
Help string // what the rule wants, e.g. "Input must be a number between 1 and 10"
Reject bool // the rule refuses it; otherwise it may be kept, marked invalid
}
InvalidEntry is an entry a cell's validation doesn't accept.
func (*InvalidEntry) Error ¶ added in v0.2.0
func (e *InvalidEntry) Error() string
type Look ¶ added in v0.2.0
type Look struct {
// Styled is set when a single-color rule applies, with its Style.
Styled bool
Style RuleStyle
// Scaled is set when a color scale colors the cell, Pos of the way
// (0 to 1) from From to To.
Scaled bool
From, To Color
Pos float64
Checkbox bool // a checkbox, checked when Checked
Checked bool
Dropdown bool // offers a list to pick from
Invalid bool // holds what its validation rule doesn't accept
}
Look is how a sheet's rules draw a cell: a conditional format's style or place on a color scale, and what its validation rule shows (a checkbox, a dropdown's marker, an invalid entry's mark).
type Macro ¶
type Macro struct {
Name string
Key string // the shortcut's digit, "0" to "9", or "" for none
Source string // the Starlark script
API int // the scripting API it was written for, MacroAPI or older
}
Macro is a saved macro.
type Name ¶
type Name struct {
Name string // as the user spelled it; formulas match it in any case
Sheet *Sheet // the sheet the range is on
Range Rect
// Lost is set when every cell of the range was deleted: formulas using
// the name show #REF!, as in Sheets. Range is then zero.
Lost bool
}
Name is a named range. Names belong to the workbook, as in Sheets, and each points at a range on one of its sheets.
type ParseError ¶
type ParseError = formula.ParseError
ParseError describes a formula that could not be parsed.
type Pivot ¶
type Pivot struct {
// Source names the sheet the data is on. Like a reference written
// with a sheet name, it follows renames, and while no sheet has the
// name the pivot shows #REF!.
Source string
// Range is the data on the source sheet; its first row holds the
// headers, which name the fields.
Range Rect
Rows []PivotGroup
Columns []PivotGroup
Values []PivotValue
Filters []PivotFilter
// RowTotals adds a Grand Total row, and a subtotal row after each
// outer group when there are several row groups. ColumnTotals adds a
// Grand Total column when there are column groups, and a subtotal
// column after each outer group when there are several.
RowTotals, ColumnTotals bool
// Lost is set when the source range was deleted.
Lost bool
}
A pivot table summarizes a range of another sheet, as Sheets' Insert > Pivot table: rows grouped by the values of some columns (Rows), spread across others (Columns), with values summarized per group (Values), and rows left out by Filters. It lives on a sheet of its own, starting at A1. The engine owns its results: they are derived cells, recomputed whenever the source's cells change, never saved (the file keeps the definition) and never edited by hand. A sheet has at most one pivot.
func FrequencyPivot ¶
FrequencyPivot is a frequency table of column col of r: each distinct value with how many rows have it and their share, most frequent first, as VisiData's Shift+F. It is a pivot like any other; it counts rows rather than values, so blanks are counted too.
type PivotFilter ¶
PivotFilter leaves out the source rows whose value in Col doesn't meet Criteria, as a filter's column does.
type PivotGroup ¶
type PivotGroup struct {
Col int // column on the source sheet
Desc bool // Z to A, or largest first
// SortBy orders the groups by their label (0) or by the grand total
// of Values[SortBy-1].
SortBy int
}
PivotGroup is a column of the source whose distinct values become rows or columns of the pivot.
type PivotInfo ¶
type PivotInfo struct {
Records int // source rows summarized
Groups int // groups of the row fields
Cells int // cells of the results
Failed bool
Duration time.Duration
}
PivotInfo describes one pivot recomputation, for telemetry. It holds counts only, never contents.
type PivotValue ¶
type PivotValue struct {
Col int
Summarize Summarize
ShowAs ShowAs
Name string // the header; "" for Sheets' "SUM of Sales"
}
PivotValue is a column of the source summarized per group.
type PointKind ¶ added in v0.2.0
type PointKind uint8
PointKind is how a color scale point is placed.
func ParsePointKind ¶ added in v0.2.0
ParsePointKind is the inverse of PointKind.String.
func PointKinds ¶ added in v0.2.0
func PointKinds() []PointKind
PointKinds lists the kinds in the order the rules editor offers them.
func (PointKind) TakesValue ¶ added in v0.2.0
TakesValue reports whether the point needs a value.
type Protection ¶ added in v0.2.0
type Protection struct {
Range Rect // the whole grid when Sheet is set
Sheet bool // the whole sheet is protected
Desc string // what the user wrote to describe it, may be ""
}
Protection is a protected range, or the whole sheet.
func (Protection) Label ¶ added in v0.2.0
func (p Protection) Label() string
Label names the protection as the UI shows it: its description, or its range, or "the sheet".
type RecalcInfo ¶
type RecalcInfo struct {
Full bool // every formula, as after loading
Evaluated int // cells marked dirty and recomputed
Cells int // cells stored on every sheet, including formatting-only ones
Volatile int // volatile formulas on every sheet, recomputed every time
Circular bool
// Duration includes the pivot tables the recalculation refreshed,
// and the recalculation of what reads their results.
Duration time.Duration
}
RecalcInfo describes one recalculation, for telemetry. It holds counts only, never contents.
type Rect ¶
Rect is an inclusive rectangular range of cells.
func ParseRange ¶
ParseRange parses "A1", "A1:B3" or 1-2-3 style "A1..B3".
func ParseRanges ¶ added in v0.2.0
ParseRanges reads ranges written as "A1:A9,C1:C9" (spaces or commas between), as the rules editor takes them.
type RemoteAnswer ¶
type RemoteAnswer = functions.RemoteAnswer
The questions and answers are the function library's (functions/remote.go); the engine's API names them too.
type RemoteCall ¶
type RemoteCall = functions.RemoteCall
The questions and answers are the function library's (functions/remote.go); the engine's API names them too.
type RemoteSource ¶
type RemoteSource = functions.RemoteSource
The questions and answers are the function library's (functions/remote.go); the engine's API names them too.
type RuleOp ¶ added in v0.2.0
type RuleOp uint8
RuleOp is a test on a cell's value, as Sheets' conditional formatting and data validation offer them. Conditional formats use them all; validation uses the comparisons (and RuleNone for "any date").
func CompareOps ¶ added in v0.2.0
func CompareOps() []RuleOp
CompareOps are the comparisons data validation offers for numbers, dates and text lengths.
func CondFormatOps ¶ added in v0.2.0
func CondFormatOps() []RuleOp
CondFormatOps lists the tests a single-color conditional format may use, in the order Sheets' menu shows them.
func ParseRuleOp ¶ added in v0.2.0
ParseRuleOp is the inverse of RuleOp.String.
func (RuleOp) Args ¶ added in v0.2.0
Args is how many values the test compares with: 0, 1, or 2 for between.
type RuleStyle ¶ added in v0.2.0
RuleStyle is what a conditional format rule does to the cells it matches: a text color, a fill, and text styles added to the cell's own.
type ScalePoint ¶ added in v0.2.0
type ScalePoint struct {
Kind PointKind
Value string // the number, percent or percentile; unused by min and max
Color Color
}
ScalePoint is a point of a color scale: where it is among the values, and its color.
func (ScalePoint) String ¶ added in v0.2.0
func (p ScalePoint) String() string
pointText writes a point as the rules editor shows it, e.g. "Min" or "Percentile 50".
type Sheet ¶
type Sheet struct {
// contains filtered or unexported fields
}
Sheet is a sparse worksheet, one of a Workbook's sheets.
func Read ¶
Read loads a file written by Write, of this or an earlier version, and returns the sheet that was shown when it was saved.
func ReadTraced ¶
ReadTraced is Read giving the workbook trace (see SetTrace) before it recalculates, so that recalculation nests in the caller's span.
func (*Sheet) AddCondFormat ¶ added in v0.2.0
func (s *Sheet) AddCondFormat(f CondFormat) error
AddCondFormat adds a rule after the others, as one undo step.
func (*Sheet) AddValidation ¶ added in v0.2.0
func (s *Sheet) AddValidation(v Validation) error
AddValidation adds a rule, taking its cells from the rules they had, as one undo step.
func (*Sheet) AdjustDecimals ¶
AdjustDecimals shows delta more (or fewer) decimal places in every non-blank number cell of r, starting from what each cell shows now.
func (*Sheet) Batch ¶
Batch runs fn as a single undo step: everything it changes is undone together, and formulas are recalculated once at the end. Batches nest; inner ones join the outermost.
func (*Sheet) Cell ¶
Cell returns the cell at a, or nil if it has neither contents nor formatting. Use Blank to test for contents.
func (*Sheet) CellFormat ¶
CellFormat returns the number format the cell at a has, its own or its row's or column's, without the one a formula infers.
func (*Sheet) CellStyle ¶
CellStyle returns the text style the cell at a shows: its own, or its row's or column's.
func (*Sheet) ChartData ¶
ChartData reads a chart's cells. Series names and labels are the cells' text as displayed.
func (*Sheet) CheckEntry ¶ added in v0.2.0
func (s *Sheet) CheckEntry(a Addr, input string) *InvalidEntry
CheckEntry reports whether the cell at a would accept input: nil when it has no rule or input meets it (blanks always do), or an *InvalidEntry. A formula is checked by the value it computes.
func (*Sheet) ClearCondFormats ¶ added in v0.2.0
ClearCondFormats takes the cells of cr out of every rule, removing rules left with no cells, as Sheets' "Clear formatting rules" for a selection.
func (*Sheet) ClearFormatting ¶
ClearFormatting resets the format and style of every cell in r, as Sheets' Format > Clear formatting.
func (*Sheet) ClearHistory ¶
func (s *Sheet) ClearHistory()
func (*Sheet) ClearNotes ¶ added in v0.2.0
ClearNotes deletes the notes in r as one undo step and returns how many there were.
func (*Sheet) ClearValidations ¶ added in v0.2.0
ClearValidations takes the cells of cr out of every rule, as Sheets' "Remove rule" does for a selection.
func (*Sheet) ColFormats ¶
ColFormats and RowFormats return the columns and rows that have a format or style of their own, by index.
func (*Sheet) ColumnFiltered ¶
ColumnFiltered reports whether the filter has criteria for column col.
func (*Sheet) CondFormats ¶ added in v0.2.0
func (s *Sheet) CondFormats() []CondFormat
CondFormats returns the sheet's conditional format rules, in the order they're tried.
func (*Sheet) Copy ¶
Copy snapshots the cells in r, and what formatting they show, for pasting. Whole columns or rows are trimmed to the cells they hold, keeping their line formats.
func (*Sheet) CreateFilter ¶
CreateFilter puts a filter on r, whose first row is the header row.
func (*Sheet) DeleteCols ¶
DeleteCols deletes n columns starting at column at.
func (*Sheet) DeleteCondFormat ¶ added in v0.2.0
DeleteCondFormat removes rule i.
func (*Sheet) DeleteName ¶
func (*Sheet) DeleteRows ¶
DeleteRows deletes n rows starting at row at. References to deleted cells become #REF!; ranges that lose some of their rows shrink.
func (*Sheet) DeleteValidation ¶ added in v0.2.0
DeleteValidation removes rule i.
func (*Sheet) Dependents ¶
Dependents returns the formula cells that read a directly, through a reference, a range or a named range: those on this sheet first in row-major order, then those on other sheets in tab order.
func (*Sheet) DisplayFormat ¶
DisplayFormat returns the format the cell at a is shown with: its own, its row's or column's, or for Automatic, the one inferred from its formula (=DATE() shows a date, =SUM(B2:B4) of currency shows currency).
func (*Sheet) DropdownItems ¶ added in v0.2.0
DropdownItems lists what a dropdown cell offers: the rule's items, or the distinct values shown in its range, in order, blanks left out.
func (*Sheet) Edge ¶
Edge returns where a data-edge jump (Ctrl+arrow in Excel, End+arrow in 1-2-3) from a in direction (dc, dr) lands. Inside a block of filled cells it stops at the block's last cell; from a blank cell, or at the end of a block, it goes to the next filled cell. With nothing filled ahead it stops at the edge of the worksheet. Rows the filter hides are skipped. Blank stretches are jumped over through the index of filled cells, so a jump costs what the block it walks holds, not the empty rows past it.
func (*Sheet) EraseRange ¶
EraseRange clears the contents of every cell in r, keeping their formatting and notes as Sheets' Delete does.
func (*Sheet) ExplainError ¶
ExplainError says why the cell at a shows an error, for the context line: where the error starts and what went wrong, e.g. "Division by zero in B3/0", or "From B5: division by zero in B3/0" when it comes from another cell. It is empty for cells without errors.
func (*Sheet) FillDown ¶
FillDown copies the top row of r into the rest of it, adjusting references (Ctrl+D). A single-row range fills from the row above. When the top rows of r start a series and the rest is blank (1, 2 and then empty cells), it continues the series instead, as dragging the fill handle would.
func (*Sheet) FillEntry ¶
FillEntry stores input in every cell of r as if it had been typed at origin and copied to each cell, adjusting references (Ctrl+Enter).
func (*Sheet) FillRight ¶
FillRight copies the left column of r into the rest of it (Ctrl+R). A single-column range fills from the column to the left. Like FillDown, it continues a series started in the leftmost columns.
func (*Sheet) FillSeries ¶
FillSeries extends src over dst, which contains it and reaches past it along one axis: down or up, right or left. Each column (or row) of src is continued on its own. It returns the range filled, as one undo step.
func (*Sheet) FilledBounds ¶
FilledBounds returns the smallest range holding every non-blank cell of r, and false if there is none.
func (*Sheet) FilterColumn ¶
FilterColumn sets the criteria for column col of the filter.
func (*Sheet) FilterRange ¶
FilterRange returns the filter's range, and false if there is no filter.
func (*Sheet) FilterValues ¶
func (s *Sheet) FilterValues(col int) []FilterValue
FilterValues lists the distinct values in column col of the filter's data rows, among the rows the other columns' criteria let through, as Sheets' "Filter by values" does. Numbers come first in numeric order, then text alphabetically, then blanks.
func (*Sheet) Find ¶
func (s *Sheet) Find(query string, o FindOptions) ([]Addr, error)
Find returns the cells matching query in reading order: row by row, left to right.
func (*Sheet) GuessChart ¶
GuessChart sets up a chart over r the way Sheets does: series down columns, a header row when the first row is text over numbers, and category labels when the first column is text.
func (*Sheet) HasRules ¶ added in v0.2.0
HasRules reports whether the sheet has conditional formats or data validation, so drawing can skip asking for looks when it has none.
func (*Sheet) HasSpills ¶ added in v0.2.0
HasSpills reports whether a formula on the sheet spills or would, so what draws the sheet can skip looking for spilled cells.
func (*Sheet) HiddenRows ¶
HiddenRows returns how many rows the filter hides.
func (*Sheet) InPivot ¶
InPivot reports whether r overlaps the pivot table's results, which can't be edited.
func (*Sheet) InSpill ¶ added in v0.2.0
InSpill returns a spilled cell in r whose anchor isn't in r, which an edit of r can't change: editing spilled cells is refused, while clearing or replacing the anchor with its spill is fine.
func (*Sheet) InsertCols ¶
InsertCols inserts n blank columns before column at.
func (*Sheet) InsertRows ¶
InsertRows inserts n blank rows before row at, shifting the rows below down and adjusting every reference to them.
func (*Sheet) Link ¶
Link returns the address a cell links to: its text when that is a URL (http, https or mailto), or the target of a HYPERLINK formula. It is empty for other cells.
func (*Sheet) Load ¶
Load stores an entry at a with its number format and style, without recalculating or recording undo. With an Automatic format the entry implies one as if typed ("$5" is currency, "9/26/2026" a date). A formula that fails to parse is rejected with a *ParseError and nothing is stored. Call RecalcAll when every cell is in.
func (*Sheet) LoadColWidth ¶
LoadColWidth sets column c's width, as a loader does: without recording undo or recalculating.
func (*Sheet) LoadCondFormats ¶ added in v0.2.0
func (s *Sheet) LoadCondFormats(fs []CondFormat) (skipped int)
LoadCondFormats adds rules as a loader does: without recording undo. Rules that don't check are left out and counted.
func (*Sheet) LoadFilter ¶
LoadFilter puts filter f on the sheet (nil removes it), as a loader does: without recording undo. Its criteria apply once values are computed, as they do whenever values change.
func (*Sheet) LoadFrozen ¶
LoadFrozen freezes the first rows rows and cols columns, as a loader does: without recording undo. SetFrozen is the undoable way.
func (*Sheet) LoadLineFormat ¶
LoadLineFormat gives a whole column (row false) or row a format and style, as an importer does, without recording undo or touching its cells; column -1 is the whole sheet.
func (*Sheet) LoadNote ¶ added in v0.2.0
LoadNote sets a note as a loader does: without recording undo.
func (*Sheet) LoadProtection ¶ added in v0.2.0
func (s *Sheet) LoadProtection(p Protection)
LoadProtection adds a protection as a loader does: without recording undo.
func (*Sheet) LoadValidations ¶ added in v0.2.0
func (s *Sheet) LoadValidations(vs []Validation) (skipped int)
LoadValidations adds rules as a loader does: without recording undo. Rules that don't check are left out and counted.
func (*Sheet) Move ¶
Move moves the cells in src so its top-left corner lands on to, as cut and paste does in Sheets, with the formatting they show; whole columns or rows take their line formats along. Formulas anywhere that referred to the moved cells follow them; references to cells the move overwrote become #REF!. It returns the destination range.
func (*Sheet) MoveCondFormat ¶ added in v0.2.0
MoveCondFormat moves rule i to position to, changing which rule wins where several apply.
func (*Sheet) MoveTo ¶
MoveTo moves the cells in src to sheet dst, src's top-left corner landing on to, as cutting on one sheet and pasting on another does in Sheets. Formulas anywhere that read the moved cells follow them to dst, naming its sheet where they need to; the moved formulas keep reading what they read, naming this sheet for cells that stayed behind. References to cells the move overwrote become #REF!.
func (*Sheet) NamedSheets ¶
NamedSheets returns the sheet names the formula at a names, as written and without repeats (in any case), or nil for anything else. Names of sheets that don't exist are included: exporters check them.
func (*Sheet) NextFilledCol ¶
NextFilledCol returns the nearest column of row, from col on in direction dir (1 or -1) and no further than limit, whose cell has contents, looking only at the columns that hold any.
func (*Sheet) NextShownRow ¶
NextShownRow returns the first row from r+d on (d is 1 or -1) that the filter doesn't hide, jumping over the hidden blank rows at the end of its range at once, and false past the edge of the sheet.
func (*Sheet) NotesIn ¶ added in v0.2.0
NotesIn returns the cells in r that have notes, in row-major order. It walks the cells the sheet holds, not r's addresses.
func (*Sheet) Paste ¶
Paste writes the clip into dst and returns the range written. Formulas shift their relative references by the distance pasted, as in Sheets; with values set, only the computed values are pasted, keeping the destination's formatting. Otherwise each cell shows the formatting its source showed (see clipfmt.go). Like Sheets, a destination that is an exact multiple of the clip's size is tiled; otherwise the clip is pasted once at dst's top-left corner.
func (*Sheet) PivotError ¶
PivotError says why the pivot shows #REF!, or "" when it doesn't.
func (*Sheet) PivotRange ¶
PivotRange returns the cells the pivot's results cover, from A1 (at least A1, even while it shows nothing), and false without a pivot.
func (*Sheet) PivotSource ¶
PivotSource returns the sheet the pivot reads, or nil when no sheet has its name.
func (*Sheet) Precedents ¶
Precedents returns the cells and ranges the formula at a reads, in the order the formula mentions them, with named ranges resolved and repeats dropped. References to sheets that don't exist are left out. It is empty for anything but a formula.
func (*Sheet) Protect ¶ added in v0.2.0
func (s *Sheet) Protect(p Protection)
Protect adds a protected range, or protects the whole sheet, as one undo step. Protecting the sheet again replaces its description.
func (*Sheet) Protecting ¶ added in v0.2.0
func (s *Sheet) Protecting(r Rect) (Protection, bool)
Protecting returns the first protection r overlaps.
func (*Sheet) Protections ¶ added in v0.2.0
func (s *Sheet) Protections() []Protection
Protections returns the sheet's protected ranges, in the order added.
func (*Sheet) RangeStats ¶
RangeStats computes Stats over r. The result is kept until a cell or value changes. A selection over a large, well-filled sheet is summed from the cells' statistics index (see rangeStats), so changing it costs a block per column plus the rows at its ends, not a read of every cell.
func (*Sheet) RecalcAll ¶
func (s *Sheet) RecalcAll()
RecalcAll recomputes every formula in the workbook. Loaders call it once the sheets are built, so it also starts a fresh undo history: loading isn't undoable.
func (*Sheet) RecalcVolatile ¶
func (s *Sheet) RecalcVolatile()
RecalcVolatile recomputes volatile formulas and their dependents on every sheet, e.g. after remote answers arrive. It doesn't touch the undo history.
func (*Sheet) Region ¶
Region returns the block of data around a, as Sheets picks the range to sort or filter when a single cell is selected: filled cells connected to a (diagonals count), and anything touching their bounding box, until nothing more touches it. A blank cell with no filled neighbors is a region of its own.
func (*Sheet) RemoteCalls ¶
func (s *Sheet) RemoteCalls(a Addr) []RemoteCall
RemoteCalls returns the questions the formula at a asks, with their current inputs, so the UI can show details or re-ask them.
func (*Sheet) RemoveFilter ¶
func (s *Sheet) RemoveFilter()
RemoveFilter removes the filter, showing every row again.
func (*Sheet) Replace ¶
Replace replaces matches of query in the cell at a and reports whether the cell changed. Formula cells are only changed when searching within formulas, as in Sheets. A replacement that turns a formula invalid is returned as an error and leaves the cell unchanged.
func (*Sheet) ReplaceAll ¶
func (s *Sheet) ReplaceAll(query, repl string, o FindOptions) (int, error)
ReplaceAll replaces every match and returns how many cells changed. It stops at the first cell whose replacement is an invalid formula.
func (*Sheet) RowFormats ¶
func (*Sheet) Set ¶
Set stores an entry at a and recalculates affected cells. An empty input erases the contents but keeps the cell's formatting. A formula that fails to parse is rejected with a *ParseError and the sheet is left unchanged. A pivot table's results can't be set: that's ErrPivotEdit.
func (*Sheet) SetChart ¶
SetChart replaces chart i, as one undo step described by label, e.g. "move chart".
func (*Sheet) SetColWidth ¶
SetColWidth sets column c's width; w <= 0 resets it to the default.
func (*Sheet) SetCondFormat ¶ added in v0.2.0
func (s *Sheet) SetCondFormat(i int, f CondFormat) error
SetCondFormat replaces rule i, as one undo step.
func (*Sheet) SetDecimal ¶
func (*Sheet) SetFormat ¶
SetFormat gives every cell in r the number format f, including blank cells, which keep it for when something is typed. Whole columns and rows keep it as their line's format rather than on each cell.
func (*Sheet) SetNote ¶ added in v0.2.0
SetNote sets the note on the cell at a as one undo step; an empty note deletes it. A pivot table's results can't take notes: ErrPivotEdit; nor can the cells an array spills into: ErrSpillEdit.
func (*Sheet) SetPivot ¶
SetPivot replaces the sheet's pivot definition as one undo step, labelled label ("edit pivot table" when empty).
func (*Sheet) SetRemote ¶
func (s *Sheet) SetRemote(r RemoteSource)
SetRemote on a sheet is its workbook's.
func (*Sheet) SetStyle ¶
SetStyle changes the text style of every cell in r with fn, e.g. to turn on bold while keeping italics. Callers wanting a specific undo label ("bold B2:B5") wrap it in Batch.
func (*Sheet) SetValidation ¶ added in v0.2.0
func (s *Sheet) SetValidation(i int, v Validation) error
SetValidation replaces rule i, as one undo step.
func (*Sheet) SheetFormat ¶
SheetFormat returns the format and style of the whole sheet, which every cell without its own, its row's or its column's shows.
func (*Sheet) ShownText ¶
ShownText is the cell's value as its format displays it, with no width limit: what filters and the values list compare.
func (*Sheet) SortRange ¶
SortRange sorts the rows of r by keys, first key first, as Sheets' Data > Sort range does (r excludes any header row). The sort is stable, so rows that tie keep their order. Only the cells inside r move. Formulas move with their rows and their relative references shift by the distance moved, as if copied there; references to the sorted cells from elsewhere are left alone. The whole sort is one undo step.
Only rows holding cells are sorted: rows whose keys are all blank go last in their order, as blank rows do, so the cost is the rows with data, however tall r is.
func (*Sheet) SpillAnchor ¶ added in v0.2.0
SpillAnchor returns the cell whose array result the cell at a shows, when a is a spilled cell (not the anchor itself).
func (*Sheet) SpillArea ¶ added in v0.2.0
SpillArea returns the cells the formula at a spills into, the anchor first, when it spills.
func (*Sheet) Unload ¶
Unload removes a cell a loader stored, as an importer does with a row that doesn't fit whole.
func (*Sheet) UnprotectRange ¶ added in v0.2.0
UnprotectRange removes every protection r overlaps, the sheet's included, as one undo step, and returns how many there were.
func (*Sheet) UsedRange ¶
UsedRange returns the smallest range from A1 covering every non-blank cell, and false if the sheet is empty.
func (*Sheet) Validation ¶ added in v0.2.0
func (s *Sheet) Validation(a Addr) (Validation, bool)
Validation returns the rule of the cell at a, if it has one.
func (*Sheet) Validations ¶ added in v0.2.0
func (s *Sheet) Validations() []Validation
Validations returns the sheet's validation rules.
type ShowAs ¶
type ShowAs uint8
ShowAs is how a summarized value shows: as itself, or as a share of a total, as Sheets' "Show as".
func ParseShowAs ¶
ParseShowAs is the inverse of ShowAs.String.
type Stats ¶
Stats summarizes the values in r, as shown in the status line for a selection. Count is non-blank cells, Nums is numeric cells.
type Style ¶
type Style struct {
Bold, Italic, Underline, Strikethrough bool
Align Align
// contains filtered or unexported fields
}
Style is a cell's text style. It is a plain value so cells can be copied freely.
type Summarize ¶
type Summarize uint8
Summarize is how a pivot value summarizes a group's cells, as Sheets' "Summarize by". Each is one entry of summaries.
func ParseSummarize ¶
ParseSummarize is the inverse of Summarize.String.
type ValidKind ¶ added in v0.2.0
type ValidKind uint8
ValidKind is what a validation rule checks.
const ( ValidList ValidKind = iota // one of Items, picked from a dropdown ValidRange // one of the values of Source, picked from a dropdown ValidCheckbox // TRUE or FALSE, drawn as a checkbox ValidNumber // a number meeting Op ValidDate // a date meeting Op; any date with RuleNone ValidLength // text whose length meets Op ValidFormula // anything for which the formula Args[0] is TRUE )
func ParseValidKind ¶ added in v0.2.0
ParseValidKind is the inverse of ValidKind.String.
func ValidKinds ¶ added in v0.2.0
func ValidKinds() []ValidKind
ValidKinds lists the kinds in the order the rules editor offers them.
func (ValidKind) Compares ¶ added in v0.2.0
Compares reports whether the kind compares with Op and Args.
type Validation ¶ added in v0.2.0
type Validation struct {
Ranges []Rect
Kind ValidKind
// Op compares numbers, dates or lengths with Args, as typed; RuleNone
// with ValidDate accepts any date. With ValidFormula, Args[0] is the
// formula, relative to the first range's top-left cell.
Op RuleOp
Args [2]string
Items []string // ValidList's items
// Source is ValidRange's range, e.g. "A2:A9" or "Lists!A1:A20".
Source string
// Reject refuses an invalid entry; otherwise it's kept and marked.
Reject bool
// Help replaces the rule's own help text, shown on the context line.
Help string
}
Validation is a data validation rule.
func ParseValidation ¶ added in v0.2.0
func ParseValidation(line string) (Validation, error)
ParseValidation reads a rule written by JSON, checking it.
func (Validation) Check ¶ added in v0.2.0
func (v Validation) Check() error
Check reports why a rule can't be used, in words for the rules editor.
func (Validation) HelpText ¶ added in v0.2.0
func (v Validation) HelpText() string
HelpText is what the context line says about a cell under the rule: the rule's own help text, or Sheets' message for its criteria.
func (Validation) JSON ¶ added in v0.2.0
func (v Validation) JSON() string
JSON writes the rule as a line of the file, e.g. {"ranges":"D2:D20","criteria":"list","items":["Yes","No"]}.
func (Validation) SourceRange ¶ added in v0.2.0
func (v Validation) SourceRange() (string, Rect, bool)
SourceRange is ValidRange's source: its sheet as written ("" for the rule's own) and range.
func (Validation) Summary ¶ added in v0.2.0
func (v Validation) Summary() string
Summary describes the rule in a few words, e.g. "Number between 1 and 10".
type Workbook ¶
type Workbook struct {
// Circular is set when the last recalculation found a cycle.
Circular bool
// contains filtered or unexported fields
}
A Workbook is an ordered list of sheets, as a Google Sheets spreadsheet: each sheet has its own cells, column widths, frozen panes, filter and charts, while named ranges, the undo history and recalculation are shared, so a formula on one sheet can read another (=Sheet2!A1, ='Q3 plan'!B2:C9) and one undo step can span sheets.
Formulas refer to other sheets by name. Renaming a sheet rewrites the formulas that name it; deleting one leaves them as written, showing #REF! ("Unresolved sheet name"), until a sheet of that name exists again, as in Sheets.
func (*Workbook) AddSheet ¶
AddSheet inserts a new, empty sheet at index at (clamped to the ends), as one undo step. An empty name picks the next SheetN.
func (*Workbook) Batch ¶
Batch runs fn as a single undo step across sheets, as Sheet.Batch; the step is shown on c.Sheet when undone.
func (*Workbook) Begin ¶
Begin opens an undo step that stays open until the returned function is called, for changes made over several calls that undo together, such as a macro run. Changes in between join it as in a Batch, and Undo and Redo do nothing while it is open. Call Settle to see the values of formulas changed so far.
func (*Workbook) ClearHistory ¶
func (w *Workbook) ClearHistory()
ClearHistory forgets all undo and redo steps.
func (*Workbook) CreatePivot ¶
CreatePivot adds a sheet named name ("" for the next Pivot Table N) right after src, holding p over r on src, as one undo step.
func (*Workbook) DefaultSummarize ¶
DefaultSummarize is how a new value summarizes column col, as in Sheets: SUM when the column holds a number, COUNTA otherwise.
func (*Workbook) DefineName ¶
DefineName names the range r on sheet s, as one undo step.
func (*Workbook) DeleteMacro ¶
DeleteMacro removes the named macro as an undo step, reporting whether there was one.
func (*Workbook) DeleteName ¶
DeleteName removes a named range, as one undo step. Formulas that use it show #NAME? until it is defined again.
func (*Workbook) DeleteSheet ¶
DeleteSheet removes s, as one undo step. Formulas on other sheets that refer to it show #REF! until it's restored or another sheet takes its name. The last sheet can't be deleted.
func (*Workbook) DuplicateSheet ¶
DuplicateSheet copies s, cells, widths, frozen panes, filter and charts, to a new sheet right after it named "Copy of ...", as Sheets' Duplicate. Formulas are copied as written, so references without a sheet name read the copy's own cells.
func (*Workbook) EditName ¶
EditName renames the named range old and points it at r on sheet s, as one undo step. Formulas that use it are rewritten to the new name, as in Sheets.
func (*Workbook) FieldName ¶
FieldName is the header of column col in the pivot's source, or "Column B" when the header is blank.
func (*Workbook) HiddenSheets ¶
HiddenSheets returns the hidden sheets, in tab order.
func (*Workbook) HideSheet ¶
HideSheet hides s, as one undo step. The last visible sheet can't be hidden.
func (*Workbook) HistoryBytes ¶
HistoryBytes estimates the memory the undo steps hold.
func (*Workbook) InsertBook ¶
InsertBook moves the sheets of src, an imported workbook, into w at index at (clamped to the ends; the UI puts them after the sheet shown), with src's named ranges, as one undo step labelled label. A sheet whose name w already has gets a number ("Sales 2"), and src's formulas follow the new name; a named range whose name w already has is left out. src is used up.
func (*Workbook) LookupName ¶
LookupName finds a named range, ignoring case.
func (*Workbook) MacroForKey ¶
MacroForKey finds the macro a shortcut digit runs.
func (*Workbook) MacroOrigin ¶
MacroOrigin identifies the computer the workbook's macros were made or trusted on, as saved in the file; "" when unknown. The UI compares it with its own to decide whether to ask before running a macro from a file made elsewhere.
func (*Workbook) NextPivotName ¶
NextPivotName is the name Sheets gives a new pivot sheet: Pivot Table 1, then 2 and so on.
func (*Workbook) PivotFilterValues ¶
func (w *Workbook) PivotFilterValues(p Pivot, col int) []FilterValue
PivotFilterValues lists the distinct values of column col of the pivot's source, among the rows its other filters let through, as a filter's values list does.
func (*Workbook) RecalcAll ¶
func (w *Workbook) RecalcAll()
RecalcAll recomputes every formula and clears the undo history.
func (*Workbook) RecalcAnswered ¶
func (w *Workbook) RecalcAnswered(calls []RemoteCall)
RecalcAnswered recomputes the formulas that were waiting for the answers to calls, and what depends on them, on every sheet: with thousands of JEV cells, an answer costs the cells that asked it, not all of them. It doesn't touch the undo history.
func (*Workbook) RenameSheet ¶
RenameSheet renames s, as one undo step, rewriting every formula that refers to it by its old name.
func (*Workbook) ReplaceSheet ¶
ReplaceSheet puts s, the sheet of an imported workbook, in the place of dst, as one undo step labelled label: it takes dst's name and position, so formulas reading dst read it, and named ranges on dst move to it. dst's charts that fit s's data stay, drawing it, and the rest go (see keepCharts); it returns what became of each. dst's cells and the rest go; undo brings them back, charts too.
func (*Workbook) SaveMacro ¶
SaveMacro stores mc in place of the macro named old, or adds it when old is "", as one undo step labelled label. Names are unique ignoring case, and so are shortcuts.
func (*Workbook) Seal ¶
func (w *Workbook) Seal()
Seal ends a run of column width changes, so the next one starts a new undo step. The UI calls it between user actions.
func (*Workbook) SetActive ¶
SetActive records which sheet is shown, for the file. It isn't an edit.
func (*Workbook) SetDecimal ¶
SetDecimal turns decimal arithmetic on or off for every sheet, as one undo step, and recalculates every formula.
func (*Workbook) SetMacroOrigin ¶
SetMacroOrigin records where the macros were made or trusted. It isn't an edit: it changes nothing a user sees, and is saved with the next save.
func (*Workbook) SetRemote ¶
func (w *Workbook) SetRemote(r RemoteSource)
SetRemote sets what answers the workbook's JEV functions: nil when no API key is configured, and the functions then evaluate to ErrNoRemote. It recomputes them, so a loaded file's questions are asked.
func (*Workbook) SetTrace ¶
SetTrace gives the workbook its owner's trace, opaque to the engine: a *telemetry.Trace from the program or import that holds the workbook, which only its goroutine uses, as with the workbook itself.
func (*Workbook) Settle ¶
func (w *Workbook) Settle()
Settle recalculates what the open step has changed so far, so formulas read inside it (by a macro, or a command it runs) see current values. Outside a step there is nothing pending.
func (*Workbook) StateID ¶
StateID identifies the workbook's contents in its undo history: undoing back to a saved state returns the ID it had when saved, so the UI can tell whether there are unsaved changes.
func (*Workbook) UndoLabel ¶
UndoLabel describes the step Undo would revert, e.g. "clear B3:B5", or "" when there is none.
func (*Workbook) UnhideSheet ¶
UnhideSheet shows s again, as one undo step.
func (*Workbook) ValueTitle ¶
func (w *Workbook) ValueTitle(p Pivot, v PivotValue) string
ValueTitle is the header of a value: its name, or Sheets' "SUM of Sales".
Source Files
¶
- cellfile.go
- cellformat.go
- chart.go
- chartfile.go
- chartopts.go
- clipfmt.go
- condfmt.go
- decimal.go
- display.go
- evaluate.go
- explain.go
- file.go
- filter.go
- find.go
- formula.go
- hidden.go
- history.go
- historysheets.go
- historysize.go
- insertbook.go
- linefile.go
- linereaders.go
- lines.go
- link.go
- load.go
- looks.go
- macros.go
- move.go
- names.go
- nav.go
- notes.go
- observe.go
- occupancy.go
- ops.go
- pivot.go
- pivotcalc.go
- pivotcols.go
- pivotfile.go
- pivotlayout.go
- protect.go
- rangeindex.go
- rangememo.go
- recalc.go
- refs.go
- remote.go
- rulefile.go
- rules.go
- series.go
- sheet.go
- sort.go
- spill.go
- stats.go
- store.go
- style.go
- trace.go
- validation.go
- values.go
- view.go
- workbook.go