The edits found two ways a saved table wouldn't reopen: cells merged in it after it was made, and a table another edit moved a region or a table onto. Tables allow merged cells, and a file's tables load where they were saved, whatever overlaps them.
- commit
- 5297cffe80e240bb19e4274bf91161f689674e4c
- parent
- c45e7e8cb7f485f18d6cb54635c7a70940729842
- author
- Dami <dami.etoile@gmail.com>
- kind
- fix risk score 2.0 of 3, Jev's estimate
| A | internal/ | 45 | ++++++++++++++++++++++++++++++ |
| M | internal/ | 7 | +---- |
| M | internal/ | 10 | +++--- |
@@ -0,0 +1,45 @@
1+package sheet2+3+import "fmt"4+5+// Tables among the random edits (randedit_test.go): made, renamed,6+// resized, styled and removed, and formulas reading them by column,7+// so their growth, header renames and bindings meet every other edit.8+9+func init() { randEdits = append(randEdits, (*randBook).editTable) }10+11+// randTables are the names the edits give tables.12+var randTables = []string{"Sales", "Costs"}13+14+func (r *randBook) editTable(e *edits) string {15+ s, name := r.sheet(e), randTables[e.n(len(randTables))]16+ w := s.wb17+ switch e.n(6) {18+ case 0:19+ rg := e.rect()20+ err := s.CreateTable(name, rg)21+ return fmt.Sprintf("table %s on %s!%s (%v)", name, s.name, rg, err)22+ case 1:23+ to := randTables[e.n(len(randTables))]24+ err := w.RenameTable(name, to)25+ return fmt.Sprintf("rename table %s to %s (%v)", name, to, err)26+ case 2:27+ rg := e.rect()28+ err := w.ResizeTable(name, rg)29+ return fmt.Sprintf("resize table %s to %s (%v)", name, rg, err)30+ case 3:31+ err := w.RemoveTable(name)32+ return fmt.Sprintf("remove table %s (%v)", name, err)33+ case 4:34+ banded, header := e.n(2) == 0, e.n(2) == 035+ err := w.SetTableStyle(name, banded, header)36+ return fmt.Sprintf("style table %s %v %v (%v)", name, banded, header, err)37+ }38+ a := e.addr()39+ in := []string{40+ "=SUM(" + name + "[Column1])", "=" + name + "[@Column2]*2", "=ROWS(" + name + "[#All])",41+ "=COUNTA(" + name + ")", "=SUM(" + name + "[[#Headers],[#Data],[Column1]:[Column2]])",42+ }[e.n(5)]43+ err := s.Set(a, in)44+ return fmt.Sprintf("%s!%s = %q (%v)", s.name, a, in, err)45+}@@ -61,7 +61,6 @@ func (t Table) Col(name string) int {
6161 var (6262 ErrNoTable = errors.New("There's no table by that name")6363 ErrTableOverlap = errors.New("A table can't overlap another table, a region or a pivot table")64- ErrTableMerged = errors.New("A table can't hold merged cells: unmerge them first")6564 )6665 6766 // tablePrefix is reserved for regions' names in formulas (nu.sales).@@ -168,8 +167,7 @@ func (w *Workbook) copiedTables(ts []Table) []Table {
168167 }169168 170169 // checkTableRange reports why r can't hold the table with key self:171-// it overlaps another table, a region or a pivot table, or holds172-// merged cells.170+// it overlaps another table, a region or a pivot table.173171 func (s *Sheet) checkTableRange(r Rect, self string) error {174172 for _, t := range s.view.tables {175173 if nameKey(t.Name) != self && overlaps(t.Range, r) {@@ -179,9 +177,6 @@ func (s *Sheet) checkTableRange(r Rect, self string) error {
179177 if _, _, ok := s.InRegion(r); ok || s.InPivot(r) {180178 return ErrTableOverlap181179 }182- if len(s.MergesIn(r)) > 0 {183- return ErrTableMerged184- }185180 return nil186181 }187182 @@ -57,17 +57,17 @@ func (s *Sheet) readTables(fts []fileTable) error {
5757 // LoadTable adds t to the sheet as a loader does, without recording5858 // undo, its cells loaded. Columns t doesn't name, or names in a number5959 // other than its range's width, are named from its header row, and the60-// names are made unique.60+// names are made unique. Its range isn't checked against what else the61+// sheet holds: edits since it was made (a region sent over it, a table62+// moved onto another) may overlap them, and the file opens as it was63+// saved.6164 func (s *Sheet) LoadTable(t Table) error {6265 if err := s.wb.checkTableName(t.Name, ""); err != nil {6366 return err6467 }65- if t.Range.To.Row == t.Range.From.Row {68+ if t.Range.To.Row == t.Range.From.Row || !t.Range.To.Valid() {6669 return fmt.Errorf("the range %s has no row below its header", t.Range)6770 }68- if err := s.checkTableRange(t.Range, ""); err != nil {69- return err70- }7171 t.Cols = columnNames(t.Cols, nil)7272 if len(t.Cols) != t.Range.To.Col-t.Range.From.Col+1 {7373 t.Cols = columnNames(s.rowTexts(Rect{From: t.Range.From, To: Addr{Col: t.Range.To.Col, Row: t.Range.From.Row}}), nil)