pyvot:可以从python脚本运行Excel VBA宏吗? [英] pyvot: can I run Excel VBA macros from python script?
本文介绍了pyvot:可以从python脚本运行Excel VBA宏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
报告
对象中加载了报告WW26blueprint_with_chart_330.xlsm
对象,代码如下( print.range
用于测试工作簿是否加载): import xl
report = xl.Workbook(Report WW26blueprint_with_chart_330.xlsm)
打印报告
打印(report.range(A1:E50)。get())
从我得到:
Pyvot是写在Excel的COM API之上。您可以随时获取
底层的COM对象,并使自己的COM调用
我的Excel文件包含以下宏: p>
Macro1
Масго2
Macro7
我可以使用python / pyvot从python脚本直接运行上述任何一个宏?
解决方案
这对我来说是这样的:
report.xlWorkbook.Application.Run('Macro1')
Say I have loaded Report WW26blueprint_with_chart_330.xlsm
in the report
object with the following code (the print.range
is used here to test that the workbook is loaded):
import xl
report = xl.Workbook("Report WW26blueprint_with_chart_330.xlsm")
print report
print(report.range("A1:E50").get())
From the pyvot documentation I get that:
Pyvot is written on top of Excel’s COM API. You can always get the underlying COM object and make COM calls yourself
My Excel file has the following macros:
Macro1
Масго2
Macro7
Can I run any of the above macros directly from the python script using python/pyvot?
解决方案
This did it for me:
report.xlWorkbook.Application.Run('Macro1')
这篇关于pyvot:可以从python脚本运行Excel VBA宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文