cat / 012
clone

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

Keep pivots, big selections and XLSX imports as fast as before

Dami committed cf897e2
A pivot finds its source's last data row once, not per row; selections
and blocks of cells as large as the sheet's cells are many read the cell
map rather than the index; XLSX imports look at the columns their data
reaches (at least 256) for widths and styles, and read a style on both A
and XFD as the sheet's.
commit
cf897e2efff656c63f87d94eafe493953160d368
parent
fb81461eeb96948648ef5db9cc265e8266a6140d
author
Dami <dami.etoile@gmail.com>
8 files changed, +64 -18
Minternal/fileio/xlsx.go5+++--
Minternal/fileio/xlsxlines.go33+++++++++++++++++++-----------
Minternal/fileio/xlsxlines_test.go16+++++++++++++++
Minternal/sheet/nav.go2+-
Minternal/sheet/pivot.go3++-
Minternal/sheet/pivotcalc.go3++-
Minternal/sheet/sheet.go2+-
Minternal/sheet/store.go18++++++++++++++++
M internal/fileio/xlsx.go +3 -2
M internal/fileio/xlsxlines.go +21 -12
@@ -46,25 +46,34 @@ func snapLines(s *sheet.Sheet, row bool) map[int]LineFormat {
4646 return out4747 }4848 49-// importXLSXColumns reads the sheet's column widths and styles; a style50-// on every column is the sheet's.51-func importXLSXColumns(x *excelize.File, b *builder, ws string, styles map[int]xlsxStyle) {49+// importXLSXColumns reads the widths and styles of the sheet's columns50+// up to its data's width (at least 256); a style on every column, the51+// last included, is the sheet's.52+func importXLSXColumns(x *excelize.File, b *builder, ws string, styles map[int]xlsxStyle, width int) {53+ styleOfCol := func(name string) (xlsxStyle, bool) {54+ if id, err := x.GetColStyle(ws, name); err == nil && id != 0 {55+ st := styleOf(x, id, styles)56+ return st, st != (xlsxStyle{})57+ }58+ return xlsxStyle{}, false59+ }60+ var whole xlsxStyle61+ if first, ok := styleOfCol("A"); ok {62+ if last, _ := styleOfCol("XFD"); last == first {63+ whole = first64+ b.s.LoadLineFormat(false, -1, first.format, first.style)65+ }66+ }5267 cols := map[int]xlsxStyle{}53- for c := range sheet.MaxCols {68+ for c := range min(max(width, 256), sheet.MaxCols) {5469 colName, _ := excelize.ColumnNumberToName(c + 1)5570 if w, err := x.GetColWidth(ws, colName); err == nil && math.Abs(w-excelDefaultWidth) >= 0.01 && math.Abs(w-9.140625) >= 0.01 {5671 b.s.SetColWidth(c, max(int(math.Round(w))+excelPadding, 1))5772 }58- if id, err := x.GetColStyle(ws, colName); err == nil && id != 0 {59- if st := styleOf(x, id, styles); st != (xlsxStyle{}) {60- cols[c] = st61- }73+ if st, ok := styleOfCol(colName); ok && st != whole {74+ cols[c] = st6275 }6376 }64- if st := cols[0]; len(cols) == sheet.MaxCols && !slices.ContainsFunc(slices.Collect(maps.Values(cols)), func(o xlsxStyle) bool { return o != st }) {65- b.s.LoadLineFormat(false, -1, st.format, st.style)66- return67- }6877 for c, st := range cols {6978 b.s.LoadLineFormat(false, c, st.format, st.style)7079 }
M internal/fileio/xlsxlines_test.go +16 -0
M internal/sheet/nav.go +1 -1
M internal/sheet/pivot.go +2 -1
M internal/sheet/pivotcalc.go +2 -1
M internal/sheet/sheet.go +1 -1
M internal/sheet/store.go +18 -0