Set default value from source using validate as list in data_validation () method of xlsxwriter in python?

I have created an excel sheet using the xlsxwriter module in python. I am trying to set a default value for a dropdown created with the data_validation () method for xlsxwriter.
However, according to the xlsxwriter documentation , it has no default if we use validate as list.

sheet.data_validation('G5', {'validate': 'list',
                             'source': ['Completed',
                                        'Pending',
                                        'Script Error']})

      

Can anyone suggest me some work to have a default and dropdown in the same cell?

+3


source to share


1 answer


As far as I know, there is no way in Excel to have a default value in dropdown data validation. Hence, it is not supported by XlsxWriter.

However, you can simply write the default in the same cell as the data validation in the XlsxWriter. For example:

import xlsxwriter

workbook = xlsxwriter.Workbook('data_validate.xlsx')
worksheet = workbook.add_worksheet()

worksheet.data_validation('B3', {'validate': 'list',
                                 'source': ['Completed',
                                            'Pending',
                                            'Script Error']})

worksheet.write('B3', 'Pending')                                        


workbook.close()

      



Output:

enter image description here

+2


source







All Articles