I have a problem, I have an Excel file (.xlsx) and this file have some buttons in it to help to change the language and a button that make a raport based of the data. The problem is...If I write something in the file and then I save it with openpyxl the file will lose those buttons and looks like a normal excel. What can I use to save that file with the same format? I installed an addin to see those buttons. What can I do?
EDIT: I tried to save it.xlsm but it doesn't open if I do that
.xlsx
dose not have macros. Save it as .xlsm
instead.
尝试这个:
wb.save('testsave.xlsm');
I had a similar problem and I have found a workaround for it:
I have an .xlsm
file that contain few sheets, one of them has some macros and buttons, I read it on python using openpyxl
function load_workbook
(and passing the param keep_vba=True
to make sure the macros are preserved), I write some data into another sheet that has no macros nor buttons, and I save the file using .save(...)
. When I open the file using excel, the macros are still there but the buttons are no longer buttons, they became images.
Added a macro that creates the buttons on file opening ( and macros enabling of course). This worked very well in my case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.