How to send input from excel to python?

1.5k Views Asked by At

I created a worksheet in excel using the python library xlsxwriter. I wrote in cell B2 "Input column to pivot on", and then in cell C2 I provided a drop down option list.

enter image description here

I created the drop down list by calling data_validation() on the worksheet.

workbook = writer.book
worksheet3 =  workbook.add_worksheet('Sheet3') 
prompt = "Select category to calculate variance of: "

worksheet3.write('B2', prompt)
worksheet3.write('C2', 'Max TemperatureF')
worksheet3.data_validation('C2', {'validate': 'list',
    'source': ['Max TemperatureF', 'Mean TemperatureF', 'Min TemperatureF', 'Max Dew PointF']})
worksheet3.set_column(2, 1, 35) # C2
worksheet3.set_column(2, 2, 20) # C2

After that I call writer.save() to save the worksheet. Now I'm trying to figure out how to get the value of cell C2. I want to add a submit button to the excel sheet in cell D2 using python. Then when the button is clicked I will grab the value of C2 using python and store the value.

Has anyone ever done anything similar to this or know how to?

2

There are 2 best solutions below

2
On BEST ANSWER

XlsxWriter is solely for writing excel files. It cannot read from them, much less respond to the click of a button inside a worksheet.

To read Excel files, you can use xlrd. To interact with Excel, take a look at xlwings.

4
On

I didn't get perfectly what you want but if it could help you coud use the exec function.

>>> string = "print 'hello'"
>>> exec string
hello