Assign Excel cell value from Datepicker widget Selection using Python

Kushal Kumaran kushal at locationd.net
Sun Jun 28 14:34:35 EDT 2020


narenchunduri at gmail.com writes:

> When I run the python code I should be able to open my Excel and when
> I click on one Excel cell I should have my datepicker widget popped up
> and I should be able to select any date from my datepicker widget as
> my Excel cell value
>
> Tried below code but in vain: (Used jupyter Notebook)
>
> from ipywidgets import widgets
> from openpyxl import *
>
> wb = load_workbook('My_Excel.xlsx')
> worksheet = wb.active
> worksheet['B1'] = 'Datepicker'
> worksheet['B2'] = widgets.DatePicker()
> wb.save('My_Excel.xlsx')
> wb.close()
> Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel

You might be asking too much from the tools.  Unless openpyxl has some
special knowledge of ipywidgets, what you're looking for won't work.
ipywidgets has web-based components, that work from web browsers.

You can use the cell data validation features to restrict the B2 cell to
a valid date value, and the cell formatting ability to set the visual
representation to a date, but that will not be sufficient to turn it
into a date picker.  You will have to deal with VBA or form components
to do that.  I'm not aware of such capabilities in the various xlsx
writing libraries.

-- 
regards,
kushal


More information about the Python-list mailing list