Reputation: 1039
I've written a python program using the openpyxl
module that uploads a formatted but otherwise blank form and fills out the form as needed from a database using pyodbc, then saves the filled out form to the desktop. The form also has some option-buttons and check-boxes that I plan to have the form automatically select through a process similar to this:
https://superuser.com/questions/385387/how-to-select-radio-buttons-by-cell-value-in-excel
The problem that I'm running into is that running my program as is creates the new excel file without the option-buttons.
The file I start with has them already in place before uploading, but the don't make it through the program into the new file (I'd add a pic but don't have enough reputation yet).
The layout looks similar to this:
>>> parts = [list of parts]
>>> workbook = load_workbook("report.xlsx")
>>> ws = workbook.get_sheet_by_name("Parts")
>>> for i in range(len(parts)):
>>>>>> Cell_part = ws.cell("A" + str(i))
>>>>>> Cell_part.value = parts[i]
>>> workbook.save("filename")
None of these have anything to do with the option-buttons, they just populate cells and are working fine. I've skimmed through the openpyxl documentation and think maybe this is a limitation of the module, but I thought I'd ask if there was something I was missing, or if you guys have any ideas for working around this. I've thought of using another module such as xlrd, but the program needs to be able to work with .xlsx files, which xlrd doesn't do.
Thanks in advance for any help.
Upvotes: 0
Views: 3010
Reputation: 19527
AFAIK buttons need VBA. There is an option for preserving VBA when working with existing files: http://openpyxl.readthedocs.org/en/latest/openpyxl.reader.html#module-openpyxl.reader.excel
Upvotes: 1