Voice from the field

Donwloads: Demo Project

The Office App, There and Back again...

August 30 2016

COM and VSTO

As office developers, I am sure you have already create tons of the VSTO and COM addins. I do remember the pain when merge some COM addins to VSTO platform. Sweet and spicy time back in days! We growing up and dropped some scaring workarounds and made refactored code easy and more supportable.

Now Microsoft come up with new "idea" - Office Apps.  Web platform! Really?  Refactoring? Again?

They said, "VSTO still been supportable. Like now you can still find working COM addin solutions. The main goal is make your Addin work on new platform including Mac and Office Online". Stop! Wait a minute Mac? Really?  

Mac OS

Yes. It perfectly doable with Office Apps. It is just a embed web browser inside of the Word/Excel instance locally or new window in Office Online. The embed browser is IE (stop! do not tell me this!). It will works on Mac OS as well.

Endless world of Web

Windows developers welcome to endless world of Web!  Do not have web silks? You kidding me! That is a time to rump up.  Office App code works in IE and support most of the popular JavaScript frameworks including JQuery, AngularJS and SignalR.

There and Back again

The biggest problem right now with Office Apps is a quite limited functionality available through the Office.js API There is two API exits right now Excel JavaScript and Word JavaScript API. Yes, they do can reach a values on the office documents and can provide user interaction options but no UDF, no Key Hooks, no ribbon customization and etc. I would not spent your time of marketing crap. API growing right now and chosen as main direction for future Office customization.

But how we workaround exited limitation?  Yes. There is a way you simply can implement whatever you need in VSTO and make you Web Page call to the VSTO to get value and return it back.  Crazy? Yes it does. Do not blame me it just temporary work around and will be eliminated as soon as API will extend according our need. Soon or likely soon. Let say in one day in the future you will get it out of box  ... but now the workaround.

 

In attached file you can find working example of integration between Office App and VSTO. That integration is made through Ajax calls to the self-hosted Web API.  Web API implemented as standalone MVC project and can be tested and hosted separately.

 

Let me give you brief details before get your hands dirty.  

  • VSTO Addin (ExcelAddInHost project) is start self-host MVC API project (AjaxAddInHost project)

  • VSTO Addin create wrappers for Excel Application objects and expose them in API project.

  • AjaxPOC project is Office App Addin. The Addin is hosted in Excel Process and available through embedded IE (AjaxPOCWeb project).

  • Strat page of the AjaxPOCWeb project is AjaxPOCWeb/App/Home/Home.html

  • When the Home page of the Office App Addin is loading it makes an Ajax call to the self-hosted MVC API to reach the VSTO addin. MVC API create controller instance and create Workbook, Worksheet and Range wrappers to expose Excel data. The data is send back as result of the Ajax Call and show on the Office App Addin page.

  • Because the REST API support CRUD operation you can easily implement Excel's Cell modification.

Note: Please do not forget about wrapping Excel object because they based on the COM wrapper and impropriate release CCW can leads a memory leaks.  

Here is a result of the execution this POC. Enjoy J