Description
Description
DeleteDataValidation does not work as expected. When calling it with sqrefs collected from a GetDataValidations call on the same sheet:
validations, err := workbook.GetDataValidations(sheetName)
if err != nil {
return fmt.Errorf("error getting data validations: %w", err)
}
var origSqrefs []string
for _, v := range validations {
origSqrefs = append(origSqrefs, v.Sqref)
}
if len(origSqrefs) > 0 {
if err := workbook.DeleteDataValidation(sheetName, origSqrefs...); err != nil {
return fmt.Errorf("error deleting original data validations: %w", err)
}
}
The data validations remain in the sheet post-deletion. Even after saving the file.
While debugging, I noticed that the delete function returns early. The object returned by the f.workSheetReader(sheet) call has a DataValidations field that is nil. Which causes the function to return nil before performing any work. This is unexpected since the GetDataValidations() call I made before, on the same sheet, successfully returned data validations:
func (f *File) DeleteDataValidation(sheet string, sqref ...string) error {
ws, err := f.workSheetReader(sheet)
if err != nil {
return err
}
ws.mu.Lock()
defer ws.mu.Unlock()
if ws.DataValidations == nil {
return nil <--------------------------------- RETURNS EARLY HERE
}
if sqref == nil {
ws.DataValidations = nil
return nil
}
}
Variables in the DeleteDataValidation call at runtime:

Variables in my code snippet (the one that calls DeleteDataValidation) at runtime:

Steps to reproduce the issue
- Open an existing Excel file with a sheet containing data validations.
- Call workbook.GetDataValidations on the sheet containing the data validations.
- Pass the Sqrefs from the returned data validations to a workbook.DeleteDataValidations call, on the same sheet.
- Pause a debugger on line 369 in datavalidation.go
- Observe the empty DataValidations member of variable ws
Describe the results you received
No deletion of specified data validations.
Describe the results you expected
Deletion of specified data validations
Go version
1.24.3
Excelize version or commit ID
2.9.1
Environment
Windows 11, Microsoft® Excel® for Microsoft 365 MSO (Version 2502 Build 16.0.18526.20286) 64-bit
Validations
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status