python加载项向导_使用Python中的win32com加载Excel加载项

I've seen from various questions on here that if an instance of Excel is opened from Python using:

xl = win32com.client.gencache.EnsureDispatch('Excel.Application')

xl.Visible = True

wb = xl.Workbooks.Open('Test.xlsx')

Then it does not load the default add-ins. I've tried forcing my add-in to load by instead running:

xl = win32com.client.gencache.EnsureDispatch('Excel.Application')

xl.Visible = True

addin = xl.Workbooks.Open('C:/path/addIn.xll')

wb = xl.Workbooks.Open('Test.xlsx')

However, when I do this an instance of Excel opens and I get a security message asking me to verify I want to open this add-in. If I click "Enable this add-in for this session only" Excel immediately closes and does not open my desired xlsx file.

Does anyone have any ideas how to force the add-in to load and then to allow me to open my file?

Thanks very much for your help!

解决方案

I have actually managed to resolve this by borrowing something from this MSDN article relating to doing the same thing with VBA:

The following now works perfectly:

xl = win32com.client.gencache.EnsureDispatch('Excel.Application')

xl.Visible = True

xl.RegisterXLL('C:/path/addin.xll')

wb = xl.Workbooks.Open('Test.xlsx')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值