This closes #1254, `DeleteDataValidation` support delete all data validations in the worksheet
This commit is contained in:
parent
7f570c74f8
commit
5beeeef570
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue