简体   繁体   English

openpyxl 和 excel 宏

[英]openpyxl and excel macros

I am on winodws 10, Python 3.7.我使用的是 winodws 10,Python 3.7。

When i work with openpyxl and .xlsm files, once my xlsm is edited/saved through openpyxl, all buttons assigned to macros disappear (the macros are still there).当我使用 openpyxl 和 .xlsm 文件时,一旦我的 xlsm 通过 openpyxl 编辑/保存,分配给宏的所有按钮都会消失(宏仍然存在)。 Here is my test code:这是我的测试代码:

import openpyxl
from openpyxl import Workbook
from openpyxl import load_workbook

wb = load_workbook(filename='my_file.xlsm', keep_vba=True)
ws = wb["sheet1"]
c = ws.cell(row = 1, column = 1)
c.value = "test"
wb.save('my_file.xlsm')

Any opinions on why the buttons disappear?关于按钮消失的原因有什么意见吗?

Thanks.谢谢。

When you save the file.保存文件时。 It basically saves as a new file instead of replacing the old one.它基本上保存为一个新文件而不是替换旧文件。 Try saving with a different name and then you can see the difference.尝试使用不同的名称保存,然后您可以看到不同之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM