在Excel Online中,OfficeJS API不再将host_Info_参数传递给Excel加载项 [英] In Excel Online, OfficeJS API is not passing the host_Info_ parameter anymore to Excel Add-In

查看:193
本文介绍了在Excel Online中,OfficeJS API不再将host_Info_参数传递给Excel加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么时候开始发生这种情况,或者情况是否已更改,但是框架未将_host_Info参数传递给Excel Online中的Excel加载项.

I don't know when this started happening or if things have changed but the _host_Info param is not being passed by the framework to my Excel Add-In in Excel Online.

它传递一个空的"et="参数,在这种情况下可以,因为我处于开发模式. Excel桌面客户端仍在传递它.

It passes an empty "et=" parameter which is OK in this case since I'm in dev mode. The Excel desktop client is still passing it.

我的加载项需要这样做才能在Excel Online和Excel for Windows之间切换功能.

This is required by my add-ins to switch functionality between Excel Online and Excel for Windows.

我检查了文档,发现没有任何更改.

I've checked the docs and can't find that anything has changed.

推荐答案

要补充Sudhi的答案:根据Sudhi答案中的链接提供的官方API,我们继续进行操作,并为Sudhi的答案添加了"shim" OfficeJsHelpers 库中的API.

To append to Sudhi's answer: with the official API coming as per the link in Sudhi's answer, we've gone ahead and also added a "shim" for the API in the OfficeJsHelpers library.

填充程序仍使用Sudhi提到的变通方法代码-window.sessionStorage['hostInfoValue']-但它将其包装在与官方Office.js中非常相似的API中.官方API可用后,我们将切换shim代码以改为使用该代码.这种方法的优点在于,如果您通过NPM软件包使用OfficeJsHelpers,那么您要做的就是更新软件包的依赖关系,突然之间,您将从非官方的,可能存在的脆弱性变通方法转向正式依赖100%的API公开的属性-所有这些都无需更改您自己的代码!同样,如果当时您决定切换回使用正式的Office.js版本,则API的相似性(本质上仅是名称空间的差异)应该使切换实现变得很简单.

The shim still uses the workaround code that Sudhi mentions -- window.sessionStorage['hostInfoValue'] -- but it wraps it in an API very similar to what is coming in the official Office.js. Once the official API is available, we'll switch the shim code to make use of that instead. The beauty of this approach is that if you use OfficeJsHelpers via an NPM package, all you have to do is update your package dependency, and you'll suddenly go from an unofficial and potentially-fragile workaround to an API that relies on 100% officially-exposed properties -- all without changing your own code! Likewise, if at that time you decide to switch back to using the official Office.js version, the similarity of the APIs (essentially just namespace differences) should make it trivial to switch over the implementations.

助手API是 OfficeHelpers.Utilities.host (将返回WORDEXCEL等)和 OfficeHelpers.Utilities.platform (将返回IOS) ,PCOFFICE_ONLINEMAC).常量在OfficeHelpers.HostTypeOfficeHelpers.PlatformType中定义.

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

您可以在 https://www.npmjs上找到NPM软件包.com/package/@ microsoft/office-js-helpers ,并通过NPM安装它,或使用CDP之类的Unpkg快速试用:

You can find the NPM package at https://www.npmjs.com/package/@microsoft/office-js-helpers, and either install it via NPM, or use a CDN like Unpkg to quickly try it out: 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");
}

我希望您能找到上述作为临时措施的帮助,并且在正式API发行后,我们一定会更新此StackOverflow线程(和OfficeJsHelpers代码).

I hope you find the above helpful as an interim measure, and we'll be sure to update this StackOverflow thread (and the OfficeJsHelpers code) once the official API is released.

这篇关于在Excel Online中,OfficeJS API不再将host_Info_参数传递给Excel加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆