How to load an Excel Addin using Interop

前端 未结 2 911
你的背包
你的背包 2020-12-17 02:11

I have an AddIn which I want to invoke through Excel interop from a C# winforms application.

I can\'t get the addin etc. to load unless I uninstall and resinstall it

2条回答
  •  不知归路
    2020-12-17 03:15

    After a while I found the answer hidden in strange places in the MS help: and this blog post.

    That isn't all the info you need though. Things to note: you must have at least one workbook open or otherwise Excel barfs. Here's some rudementry code to get started:

    var excel = new Application();
    var workbook = excel.workbooks.Add(Type.Missing);
    excel.RegisterXLL(pathToXll);
    excel.ShowExcel();
    

    If you want you can close the temporary workbook (if you've run some macros etc.) and remember to tidy everything up with plenty of calls to Marshal.ReleaseComObject!

提交回复
热议问题