简体   繁体   English

StorageEvent在Excel for Windows中不起作用

[英]StorageEvent does not work in Excel for Windows

As some existing threads suggest (eg, one , two , three ), current Dialog Box does not provide an API to send regularly messages from the host page (eg, task pane) to the Dialog box. 正如一些现有线程所暗示的(例如, ),当前对话框不提供API以定期将消息从主机页面(例如,任务窗格)发送到对话框。

So I have to look for a workaround: we reserve a variable message in localStorage , then we make the Dialog box check regularly if the value of message changes. 所以我必须寻找一个解决方法:我们在localStorage保留一个变量message ,然后我们定期检查对话框是否message的值发生了变化。 It is like manually implementing an event listener by localStorage . 这就像是通过localStorage手动实现事件监听器。

Does anyone know how to implement that in a sure and efficient way (given JavaScript isn't a multi-threaded language)? 有谁知道如何以一种确定有效的方式实现它(给定JavaScript不是一种多线程语言)? I don't want this listener to be costly, and what would be the appropriate interval to set? 我不希望这个监听器成本高昂,设置的适当间隔是多少?

Edit 1: 编辑1:

I tried the StorageEvent that @PatrickEvans suggested. 我尝试了@PatrickEvans建议的StorageEvent。 For both the add-in and the dialog site, we need to implement a sendMessage... and a receiveMessage... by the variables messageFromHostToSite and messageFromSiteToHost in storage. 对于加载项和对话框站点,我们需要通过存储中的变量messageFromHostToSitemessageFromSiteToHost实现sendMessage...receiveMessage...

It worked in Excel Online in Chrome, and in Excel Online in IE 11. However, it did NOT work in Excel 2016 for Windows 7 or 10; 它适用于Chrome中的Excel Online和IE 11中的Excel Online。但是,它在Excel 2016 for Windows 7或10中不起作用; we can set items to localStorage and get them back, changing localStorage seems to not fire anything. 我们可以将项目设置为localStorage并将其取回,更改localStorage似乎不会触发任何内容。

So could anyone confirm that StorageEvent is indeed not supported in Excel 2016 for Windows 7 or 10? 那么有人可以确认Excel 2016 for Windows 7或10确实不支持StorageEvent吗? In that case, I am still looking for other workarounds... 在这种情况下,我仍在寻找其他解决方法......

Edit 2: 编辑2:

I finally made a simplified example: here is the xml file , which calls the add-in and the site . 我最后做了一个简化的例子:这是xml文件 ,它调用加载项站点 It works well in Excel Online, but does NOT fire events in Excel for Windows. 它在Excel Online中运行良好,但不会在Excel for Windows中触发事件。

在此输入图像描述

I had similar issues communicating between apps. 我在应用程序之间进行通信时遇到类 In my testing, Excel Online storageEvent works because the communication is between browser tabs of the same "instance". 在我的测试中,Excel Online storageEvent有效,因为通信是在同一“实例”的浏览器选项卡之间进行的。 With Excel for Windows, 2 add-ins are in separate browser "instances"; 使用Excel for Windows,2个加载项位于单独的浏览器“实例”中; which don't communicate storageEvents. 哪些不通信storageEvents。 Worse yet was Office for Mac (WebKit); 更糟糕的是Office for Mac(WebKit); which did not communicate storageEvents and also could not read storage changes from the other app unless they were restarted -- I believe this is because the storage values were cached for the instance (not written to disk and not visible to the other instance/app). 它没有传递storageEvents,也无法从其他应用程序读取存储更改,除非它们重新启动 - 我相信这是因为存储值是为实例缓存的(不写入磁盘而对其他实例/应用程序不可见) 。

So, I believe Excel Online could use StorageEvents, Excel for Windows would require polling (eg check every second), and Excel for Mac may require a server-based solution, such as WebSockets. 因此,我相信Excel Online可以使用StorageEvents,Excel for Windows需要轮询(例如每秒检查一次),Excel for Mac可能需要基于服务器的解决方案,例如WebSockets。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM