In Office Excel, the OfficeJS API no longer passes the host_Info_ parameter for the Excel add-in

I do not know when this happened, or if something changed, but the _host_Info parameter _host_Info not passed by the framework of my Excel add-in to Excel Online.

It skips the empty parameter "et=" , which in this case is fine, since I'm in dev mode. The Excel desktop client still passes it.

This is necessary for my add-ons to switch functions between Excel Online and Excel for Windows.

I checked the documents and cannot find that something has changed.

+3
source share
3 answers

To add the answer to Sudhi: with the official API following the link in Sudhi's answer, we went further and added a β€œpadding” for the API to the OfficeJsHelpers Library .

The pad still uses a workaround that Sudhi mentions - window.sessionStorage['hostInfoValue'] , but it wraps it in an API very similar to what is included in the official Office.js. After the official API is available, we will replace the gasket code to use this instead. The beauty of this approach is that if you use OfficeJsHelpers through the NPM package, all you have to do is update the dependency of your package and you will suddenly switch from an unofficial and potentially fragile workaround to an API that relies on 100% officially - proposed properties - all without changing your own code! Similarly, if at that time you decided to return to using the official version of Office.js, then the similarity of the API (essentially just differences in the namespace) should make switching implementations trivial.

The auxiliary APIs are OfficeHelpers.Utilities.host (which will return WORD , EXCEL , etc.) and OfficeHelpers.Utilities.platform (which will return IOS , PC , OFFICE_ONLINE or MAC ). Constants are defined in OfficeHelpers.HostType and OfficeHelpers.PlatformType .

You can find the NPM package at https://www.npmjs.com/package/@microsoft/office-js-helpers and either install it via NPM or use CDN like Unpkg to quickly try this: https: // unpkg .com / @ microsoft / office-js-helpers@0.4.2 /dist/office.helpers.min.js

 console.log(OfficeHelpers.Utilities.host); console.log(OfficeHelpers.Utilities.platform); if (OfficeHelpers.Utilities.platform === OfficeHelpers.PlatformType.OFFICE_ONLINE) { console.log("Yep, I'm on the web client"); } 

I hope you find the above useful information as an interim measure, and we will definitely update this StackOverflow stream (and OfficeJsHelpers code) after the release of the official API.

+3
source

UPDATE:

Please see my answer above instead ( fooobar.com/questions/994931 / ... ), since a script is now possible.


[Old answer:]

Jim, could you describe your script more? Why do you need to distinguish between Online and Desktop?

The disappearance of host_info_ : you will not find it in the documents, because host_info_ has never been in the documents. All that is not documented is the internal API, which can change as necessary in the internal work of Office.js. We take support very seriously, but only for official <documented actual APIs.

Without the API, not much can be done to talk about everything (more precisely, not to rely on other bits of internal work, which can also change over time). We discussed this earlier, but it was surprisingly difficult to point out a specific scenario when the platform information was necessary and legal ("legal" in the sense that if you use the platform information to check the availability of the API, for example, that we we want to do you, we want to use Office.context.requirements.isSetSupported ) instead.

If you can share your details about the script, I could give you an alternative way to determine what you need, or have a reliable script to return to the team.

+1
source

Jim and others that may be affected by this change: unfortunately, an unrelated change designed to improve the add-in caused the removal of the query string parameter in the online platform. Please note that the URL request parameters and session storage parameters are used to start and configure the add-in environment and not for developers to consume. However, we understand the importance of this for developers, as described in this thread.

Therefore, we are adding formal APIs to make this information available. See Specifications Describing Future APIs: https://github.com/OfficeDev/office-js-docs/tree/ContextAdditions_OpenSpec

Until the APIs are available (should be very soon), you can use the following workaround. The same request host_info_ parameter value is available in the following variable: window.sessionStorage.hostInfoValue . Note that this should be considered a temporary measure, and you should switch to using the formal API as soon as they become available. . I update this thread when I release the API, which should be available for all supported versions of Office.

If you have any comments, leave your comments on the specifications directly in the Github specification branch using the provided links.

+1
source

All Articles