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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Once I call writer.save() with the file I created with xslxwriter, I can call openpyxl to read the data from it.
Yes, and you could use xlwings to make the button call Python code.
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

4 Comments

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
ehm, isn't Visual Basic better to do this?
It probably is in this one instance but collectively the project I'm working on is much easier in python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.