I'm using openpyxl ws.add_data_validation to add some validation to a cell in Excel. However, I'm finding that if the cell has some previous validation in place then it doesn't seem to take the new validation when I subsequently open it in the Excel application. If I manually clear the previous validation from the target file before I run the program then it takes the new validation fine. My code is:
dv = DataValidation(type='list', formula="{0}!$B$2:$B$18".format(quote_sheetname('values')))
ws.add_data_validation(dv)
row = 3
while row <= ws.max_row:
dv.add('F{}'.format(row))
row += 1
I think I may need to remove the existing validation before doing the dv.add command but I can't see anything in the docs about removing pre-existing validation.
Does anyone know a way to do this?