Load Excel add-in using win32com from Python

后端 未结 3 525
野的像风
野的像风 2021-02-09 20:47

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.Applicat         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 21:25

    I had the same problem, but couldn't use xl.RegisterXLL('C:/path/addin.xla') from the accepted answer, because it only works with .XLL files, and I had a .XLA file.

    Instead, I found that this worked:

    xl = win32com.client.gencache.EnsureDispatch('Excel.Application')
    
    # Need to load the addins before opening the workbook
    addin_path = r'C:\path\addin.xla'
    xl.Workbooks.Open(addin_path)
    xl.AddIns.Add(addin_path).Installed = True
    
    wb = xl.Workbooks.Open(r"C:\my_workbook.xlsm")
    

提交回复
热议问题