This closes #1254, `DeleteDataValidation` support delete all data validations in the worksheet

pull/2/head
z.hua 3 years ago committed by GitHub
parent 7f570c74f8
commit 5beeeef570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -262,8 +262,9 @@ func (f *File) AddDataValidation(sheet string, dv *DataValidation) error {
} }
// DeleteDataValidation delete data validation by given worksheet name and // DeleteDataValidation delete data validation by given worksheet name and
// reference sequence. // reference sequence. All data validations in the worksheet will be deleted
func (f *File) DeleteDataValidation(sheet, sqref string) error { // if not specify reference sequence parameter.
func (f *File) DeleteDataValidation(sheet string, sqref ...string) error {
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
if err != nil { if err != nil {
return err return err
@ -271,7 +272,11 @@ func (f *File) DeleteDataValidation(sheet, sqref string) error {
if ws.DataValidations == nil { if ws.DataValidations == nil {
return 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 { if err != nil {
return err return err
} }

@ -171,4 +171,8 @@ func TestDeleteDataValidation(t *testing.T) {
// Test delete data validation on no exists worksheet. // Test delete data validation on no exists worksheet.
assert.EqualError(t, f.DeleteDataValidation("SheetN", "A1:B2"), "sheet SheetN is not exist") 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)
} }

Loading…
Cancel
Save