cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / sheet / load.go
load.go 2.1K
1package sheet23// Loaders (the native file reader, importers of other formats) build a4// sheet cell by cell and recalculate once at the end.56// Load stores an entry at a with its number format and style, without7// recalculating or recording undo. With an Automatic format the entry8// implies one as if typed ("$5" is currency, "9/26/2026" a date). A9// formula that fails to parse is rejected with a *ParseError and nothing10// is stored. Call RecalcAll when every cell is in.11func (s *Sheet) Load(a Addr, input string, f Format, st Style) error {12 if !a.Valid() {13 return nil14 }15 c, err := newCell(input, f, st, f.IsZero())16 if err != nil {17 return err18 }19 if c == nil {20 return nil21 }22 s.place(a, c)23 return nil24}2526// LoadColWidth sets column c's width, as a loader does: without27// recording undo or recalculating.28func (s *Sheet) LoadColWidth(c, w int) {29 if c >= 0 && c < MaxCols {30 s.setWidth(c, w)31 }32}3334// LoadFitWidths widens each column of the used range whose width isn't35// set to its widest text among the first rows (a header and a sample36// below it), capped, as a table a region shows is fitted: what an37// importer does for a format that keeps no widths of its own (CSV,38// JSON). Without recording undo.39func (s *Sheet) LoadFitWidths() {40 if used, ok := s.UsedRange(); ok {41 s.fitTable(used.From, used.To.Row-used.From.Row+1, used.To.Col-used.From.Col+1)42 }43}4445// Unload removes a cell a loader stored, as an importer does with a row46// that doesn't fit whole.47func (s *Sheet) Unload(a Addr) { s.place(a, nil) }4849// LoadFrozen freezes the first rows rows and cols columns, as a loader50// does: without recording undo. SetFrozen is the undoable way.51func (s *Sheet) LoadFrozen(rows, cols int) {52 s.view.frozenRows, s.view.frozenCols = clampInt(rows, 0, MaxFrozen), clampInt(cols, 0, MaxFrozen)53}5455// LoadFilter puts filter f on the sheet (nil removes it), as a loader56// does: without recording undo. Its criteria apply once values are57// computed, as they do whenever values change.58func (s *Sheet) LoadFilter(f *Filter) {59 s.view.filter = f.clone()60 s.hidden.valid = false61}