2

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?

Alex F
  • 2,086
  • 4
  • 29
  • 67

2 Answers2

2

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.

Zenadix
  • 15,291
  • 4
  • 26
  • 41
0

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
Alessio Ragno
  • 476
  • 1
  • 6
  • 20
  • Basically I'm trying to grab the value of a cell in excel using python. I already have a small sample of code that grabs the value --< workbook = load_workbook(filename="Weather_Data1.xlsx") , worksheet3 = workbook.get_sheet_by_name('Sheet3'), print worksheet3['C2'].value >-- But I want to create a submit button in excel using python that only when clicked I execute the code above – Alex F Jun 12 '15 at 15:20
  • ehm, isn't Visual Basic better to do this? – Alessio Ragno Jun 13 '15 at 16:05
  • It probably is in this one instance but collectively the project I'm working on is much easier in python – Alex F Jun 14 '15 at 16:43
  • Try this: http://stackoverflow.com/questions/3567365/calling-python-script-from-excel-vba – Alessio Ragno Jun 14 '15 at 17:47