Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if an Office Add-in is running under Excel or Excel Online?

I'm writing an Office Add-in (formerly, Apps for Office). I'm using office.js and in some point of code I want to check if the app is running in excel (desktop software) or running on the web (Excel Online)

Something like:

if (Office.IsRunningOnWeb){
    // Do something.
}
like image 847
mehrandvd Avatar asked Jun 01 '15 05:06

mehrandvd


People also ask

Does Excel online support add-ins?

Browse for the add-in you want. You can browse the whole store by selecting All or by a specific category such as Productivity. You can filter results by the add-in's name or its rating, or try the Suggested for you option. You can also search for an add-in via the search box.

What is the difference between COM add-in and Excel add-in?

Excel add-ins are different from COM and VSTO add-ins, which are earlier Office integration solutions that run only in Office on Windows. Unlike COM add-ins, Excel add-ins do not require you to install any code on a user's device, or within Excel.

What is add-ins registered and currently running in your Office program?

On the Tools menu, click Trust Center, and then click Add-ins. View the add-ins and application extensions that are categorized as follows: Active Application Add-ins Lists the extensions that are registered and currently running in your Office program.


3 Answers

@Mehrandvd, if I may ask, what do you need this distinction for (e.g,. what would you do different based on knowing that you're in Excel Online vs. the Desktop)? I work on the Office.js APIs, so I'm happy to channel your feedback to my team, if you can provide some specifics.

If you need this distinction for feature detection, I would recommend checking the API Requirement sets instead, via a new (but back-ported to all endpoints) API, Office.context.requirements.isSetSupported(name, version). Please see my answer at Neat ways to get environment (i.e. Office version).

If it's due to some API differences you're seeing between the Excel desktop vs Online versions, the goal is for the APIs to behave the same across endpoints, so it may be a bug. If you let me know the specifics, I can follow up.

Re. the answer mentioned by @Afshin -- it may work, but just be aware that it's not public API but rather the internal workings that you're testing against, so there's a chance that this approach would stop working in the future... The only publically-exposed namespace is Office (and, with the new Excel and Word APIs released in Sept. 2015, also Excel and Word and OfficeExtension).

Hope this helps!

~ Michael Zlatkovsky

   Developer on Office Extensibility team, MSFT

PS: Please use the office-js tag for tagging these sorts of questions in the future; this is the stackoverflow tag that the Office Extensibility team at Microsoft actively looks at.

like image 177
Michael Zlatkovsky - Microsoft Avatar answered Nov 01 '22 08:11

Michael Zlatkovsky - Microsoft


You can use document type:

if (Microsoft.Office.WebExtension.context.document instanceof OSF.DDA.ExcelWebAppDocument) {
                                    //Your app running on the web
                                }

if (Microsoft.Office.WebExtension.context.document instanceof OSF.DDA.ExcelDocument) {
                                    //Your app running in excel
                                }
like image 33
Afshin Alizadeh Avatar answered Nov 01 '22 09:11

Afshin Alizadeh


The question is how do you do it, not why would you want to. There are numerous reasons why you might want to differentiate. Put in this check as follows:

if (window.top == window) {
//the add-in is not running in Excel Online
}
else
{
//the add-in is running in Excel online
}
like image 32
Sturb Avatar answered Nov 01 '22 09:11

Sturb