This project has moved. For the latest updates, please go here.

Converting Interop object to NetOffice Object

Oct 27, 2015 at 12:17 PM
Edited Oct 27, 2015 at 12:17 PM
Hi,

I'm converting a VSTO project to NetOffice because your library looks very promising (and the COM management wasn't taking into account almost anywhere).

The default vsto add-in template contains this:
public sealed partial class MyAddIn : Microsoft.Office.Tools.AddInBase {
    public Microsoft.Office.Interop.Excel.Application Application;

    protected override void Initialize() {
        this.Application = this.GetHostItem<Microsoft.Office.Interop.Excel.Application>(typeof(Microsoft.Office.Interop.Excel.Application), "Application");
    }
}

How can I "convert" this Interop.Excel.Application to a NetOffice object? And is this possible with other Interop objects?
Coordinator
Nov 5, 2015 at 7:21 PM
hey men,

NetOffice is a wrapper arround the proxies. Its regardless from early- or latebind, it was the same instances/objects all the time.
BTW: your scenario is also currently my favourite. Combine VSTO and NetOffice is very powerful. best of both worlds

In NetOffice 1.7.3(?) you have to you use the ctor. Something like this.

NetOffice.ExcelApi.Application excelHost = new NetOffice.ExcelApi.Application(null, Application);

More specific for you:

protected override void Initialize()
{
    this.Application = this.GetHostItem<Microsoft.Office.Interop.Excel.Application>(typeof(Microsoft.Office.Interop.Excel.Application), "Application");
    NetOffice.ExcelApi.Application excelHost = new NetOffice.ExcelApi.Application(null,  this.Application);
}

Now you have been created a true-managed versionless wrapper arround the interop proxy.
The upcoming NO realease is more familiar to VSTO here. I'm sorry for the convenience. NetOffice is started as a very simple/stupid lightweight wrapper and currently growing up to a real VSTO opponent. (because VSTO is no longer made)

*Sebastian
Nov 5, 2015 at 8:18 PM
Seems good, will try. Thanks!