diff --git a/datavalidation.go b/datavalidation.go index 4df2c505..1b06b6a7 100644 --- a/datavalidation.go +++ b/datavalidation.go @@ -262,8 +262,9 @@ 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 @@ -271,7 +272,11 @@ func (f *File) DeleteDataValidation(sheet, sqref string) error { 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 } diff --git a/datavalidation_test.go b/datavalidation_test.go index 9ef11dcd..80cbf595 100644 --- a/datavalidation_test.go +++ b/datavalidation_test.go @@ -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) }