Question

I have an excel add-in i created. What i want to do is to open an excel document in c# (ASP.NET) and run some code in the add-in and then return the excel document as an html page.

Can this be done?

Was it helpful?

Solution

In the Com add-in i had to add:

public partial class ThisAddIn
{
    ...
    protected override object RequestComAddInAutomationService()
    {
         if (addinUtilities == null)
         {
              addinUtilities = new AddinUtilities();
         }
         return addinUtilities;
    }
...
}

You should return an object from this function, this object can later be used in interop as in the code snippet below. add any functionality you want to expose to this object.

Then use the addin as follows:

Application app = new Application();
var myAddin = app.COMAddIns;
var count = myAddin.Count;
COMAddIn addin;
for (int i = 1; i <= count ; i++) // not zero indexed
{
    addin = myAddin.Item(i);
    var ob = addin.Object;
    var str = addin.ProgId;
    if (ob != null)
    {
         ob.RunQuery(ws);
    }
}

As you can see i have not found a good way of identifying my add-in (if anybody knows of one i would like to hear), but you can iterate over them and check the progId.

addin.Object is the object we returned from RequestComAddInAutomationService.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top