Keep all cells value in the table range when deleting table (#1684)
This commit is contained in:
parent
95fc35f46c
commit
07f2c6831a
12
table.go
12
table.go
|
@ -196,18 +196,6 @@ func (f *File) DeleteTable(name string) error {
|
|||
if ws.TableParts.Count = len(ws.TableParts.TableParts); ws.TableParts.Count == 0 {
|
||||
ws.TableParts = nil
|
||||
}
|
||||
// Delete cell value in the table header
|
||||
coordinates, err := rangeRefToCoordinates(table.Range)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = sortCoordinates(coordinates)
|
||||
for col := coordinates[0]; col <= coordinates[2]; col++ {
|
||||
for row := coordinates[1]; row < coordinates[1]+1; row++ {
|
||||
cell, _ := CoordinatesToCellName(col, row)
|
||||
err = f.SetCellValue(sheet, cell, nil)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,11 +122,19 @@ func TestDeleteTable(t *testing.T) {
|
|||
f.Sheet.Delete("xl/worksheets/sheet1.xml")
|
||||
f.Pkg.Store("xl/worksheets/sheet1.xml", MacintoshCyrillicCharset)
|
||||
assert.EqualError(t, f.DeleteTable("Table1"), "XML syntax error on line 1: invalid UTF-8")
|
||||
// Test delete table with invalid table range
|
||||
// Test delete table without deleting table header
|
||||
f = NewFile()
|
||||
assert.NoError(t, f.AddTable("Sheet1", &Table{Range: "A1:B4", Name: "Table1"}))
|
||||
f.Pkg.Store("xl/tables/table1.xml", []byte("<table name=\"Table1\" ref=\"-\" />"))
|
||||
assert.EqualError(t, f.DeleteTable("Table1"), ErrParameterInvalid.Error())
|
||||
assert.NoError(t, f.SetCellValue("Sheet1", "A1", "Date"))
|
||||
assert.NoError(t, f.SetCellValue("Sheet1", "B1", "Values"))
|
||||
assert.NoError(t, f.UpdateLinkedValue())
|
||||
assert.NoError(t, f.AddTable("Sheet1", &Table{Range: "A1:B2", Name: "Table1"}))
|
||||
assert.NoError(t, f.DeleteTable("Table1"))
|
||||
val, err := f.GetCellValue("Sheet1", "A1")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Date", val)
|
||||
val, err = f.GetCellValue("Sheet1", "B1")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Values", val)
|
||||
}
|
||||
|
||||
func TestSetTableHeader(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue