2

I have seen another answer to this, but I could not get it to work and I was not allowed to ask another question.

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

I find that there are often occurrences where Excel Online just does not behave the same as Excel Desktop. I know it should but it doesn't, so I really need to be able to control behaviour to get me out of a hot spot.

How can I tell which version of Excel I am using.

I have seen the following code, but it just hangs my javascript:

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
                            }

The issue is to do with OSF.DDA.... These do not come up in my intellisense, so I wonder, do I have something missing?

Community
  • 1
  • 1
Sturb
  • 71
  • 4
  • I'm also looking for a way of doing this in order to have allow different ADAL login flows when running in online and desktop to get around iFrame issues. – JayChase Mar 29 '16 at 05:01

4 Answers4

1

The quick answer is that you can check if the add-in is running in an iframe:

if(window.top == window){
    // the add-in is not running in Excel Online
}

However, we recommend that you check for the actual behaviour or capability that you need - this approach will be more robust to changes in the future. Let's say you need a particular Excel API that's currently unavailable in Excel Online. Then follow the guidance for specifying Office hosts and API requirements. For example, you could check:

if (Office.context.requirements.isSetSupported("ExcelApi", 1.3)){
    // use the Excel 1.3 API set which currently isn't available in Excel Online but will be in the future.
}

Another possibility is that what you actually need is a particular browser feature that might not be available depending on what browser the user is accessing Office Online with. Then my recommended solution would again be to check for the capability you need directly, such as:

if(window.localStorage){
    // the browser that the user is accessing Excel Online with has the local storage capability that you need.
}

-Michael (PM for Office add-ins)

Michael Saunders
  • 2,662
  • 1
  • 12
  • 21
  • Thanks Michael. The Window.top answer worked nicely for me. – Sturb Apr 06 '16 at 16:44
  • Checking for behaviour or capability is ideal but not always suitable. For instance, we are using localStorage to send messages from the parent to the dialog, and in the Desktop version of excel, the storage event doesn't fire in the dialog. So we need to use polling in the Desktop version, but as far as I know there is no way to detect this using `Office.context.requirements`. – extremeandy Apr 07 '20 at 22:08
  • Also, the `window.top == window` test doesn't help if you run it from the dialog - it returns `true` for Excel Online and Desktop. – extremeandy Apr 07 '20 at 22:13
1

The current way to do this is:

if (Office.context.platform === Office.PlatformType.OfficeOnline) {
   ...
}
extremeandy
  • 503
  • 3
  • 13
-1

I used a no script option. Function INFO works in desktop excel but gives error in web based view.

=INFO("DIRECTORY")

In Desktop view it gives a path, in web it gives error, so I use =ISERROR() to check, which view is used.

ranno
  • 1
  • ranmo, that function will not work in Excel Online, so it's not a reliable test unless, as @Eric Barrows suggests, you trap the error (and accept that method's limitations.) – John Joseph Oct 26 '21 at 18:31
-1

Like ranno said but I use...

=IFERROR(IF(INFO("system")="pcdos","PC","Net"),"Net")

Because for my purpose Mac is as bad as Web.

letmejustfixthat
  • 3,379
  • 2
  • 15
  • 30