Skip to content

Commit

Permalink
This closes #1254, DeleteDataValidation support delete all data val…
Browse files Browse the repository at this point in the history
…idations in the worksheet
  • Loading branch information
z-hua authored Jun 15, 2022
1 parent 7f570c7 commit 5beeeef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions datavalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,21 @@ func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
}

// DeleteDataValidation delete data validation by given worksheet name and
// reference sequence.
func (f *File) DeleteDataValidation(sheet, sqref string) error {
// reference sequence. All data validations in the worksheet will be deleted
// if not specify reference sequence parameter.
func (f *File) DeleteDataValidation(sheet string, sqref ...string) error {
ws, err := f.workSheetReader(sheet)
if err != nil {
return err
}
if ws.DataValidations == nil {
return nil
}
delCells, err := f.flatSqref(sqref)
if sqref == nil {
ws.DataValidations = nil
return nil
}
delCells, err := f.flatSqref(sqref[0])
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions datavalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,8 @@ func TestDeleteDataValidation(t *testing.T) {

// Test delete data validation on no exists worksheet.
assert.EqualError(t, f.DeleteDataValidation("SheetN", "A1:B2"), "sheet SheetN is not exist")

// Test delete all data validations in the worksheet
assert.NoError(t, f.DeleteDataValidation("Sheet1"))
assert.Nil(t, ws.(*xlsxWorksheet).DataValidations)
}

0 comments on commit 5beeeef

Please sign in to comment.