简体   繁体   English

如何检测用户使用的是 Excel 在线版还是 Excel 桌面版

[英]How do I detect if the user is using Excel online or Excel desktop

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? 如何确定 Office 加载项是在 Excel 还是 Excel Online 下运行?

I find that there are often occurrences where Excel Online just does not behave the same as Excel Desktop.我发现经常出现 Excel Online 与 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.我如何知道我使用的是哪个版本的 Excel。

I have seen the following code, but it just hangs my javascript:我已经看到以下代码,但它只是挂起我的 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?问题与 OSF.DDA 有关....这些在我的智能感知中没有出现,所以我想知道,我是否缺少某些东西?

The quick answer is that you can check if the add-in is running in an iframe:快速回答是您可以检查加载项是否在 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.假设您需要当前在 Excel Online 中不可用的特定 Excel API。 Then follow the guidance for specifying Office hosts and API requirements .然后按照指定 Office 主机和 API 要求的指南进行操作。 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.另一种可能性是,您实际需要的是特定的浏览器功能,根据用户访问 Office Online 所使用的浏览器,该功能可能不可用。 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(Office 插件的 PM)

I used a no script option.我使用了无脚本选项。 Function INFO works in desktop excel but gives error in web based view.函数 INFO 在桌面 excel 中工作,但在基于 Web 的视图中出错。

=INFO("DIRECTORY") =信息(“目录”)

In Desktop view it gives a path, in web it gives error, so I use =ISERROR() to check, which view is used.在桌面视图中它给出了一个路径,在 web 中它给出了错误,所以我使用 =ISERROR() 来检查使用了哪个视图。

The current way to do this is:目前的做法是:

if (Office.context.platform === Office.PlatformType.OfficeOnline) {
   ...
}

Like ranno said but I use...就像ranno说的,但我用...

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

Because for my purpose Mac is as bad as Web.因为就我而言,Mac 和 Web 一样糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用桌面中的javascript检测用户是否在底部 - how to detect user is in bottom using javascript in desktop 如何在线在 Excel 中创建计数器 (Excel 365) - How to create a counter in Excel online (Excel 365) 如何检测桌面和移动Chrome用户代理? - How do you detect between a Desktop and Mobile Chrome User Agent? 如何使用office script excel online在office 365中发送电子邮件 - How to send email in office 365 using office script excel online 如何检测用户使用的是手机,平板电脑还是台式机并重定向它们? - How to detect whether the user is using mobile, tablet or desktop and redirect them? 如何使用JavaScript检测用户的IP地址? - How do I detect a user's IP address using javascript? 如何检测 Excel Javascript 加载项范围内的合并单元格? - How do I detect merged cells in a range from an Excel Javascript Add-In? 如何在 vue 组件中使用 Maatwebsite 导入 excel 文件? - How do I import a excel file using Maatwebsite in a vue component? 使用HTML,如何将文件作为excel文件打开? - Using HTML, How do I open a file as an excel file? 如何确定 Office 加载项是在 Excel 还是 Excel Online 下运行? - How to determine if an Office Add-in is running under Excel or Excel Online?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM