获取PowerPoint内容加载项(Office.js)的幻灯片索引或可见性状态 [英] Get slide index or visibility state of PowerPoint content addin (Office.js)

查看:127
本文介绍了获取PowerPoint内容加载项(Office.js)的幻灯片索引或可见性状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Office.js API编写PowerPoint内容加载项.我需要办法 对于该插件的每个实例,确定包含的索引 幻灯片,或者,如果不可能,则为该插件的可见性状态(即 当前是否在屏幕上可以看到包含的幻灯片.

I'm writing a PowerPoint content addin using Office.js API. I need a way for each instance of that addin to determine the index of the containing slide, or, if this is impossible, the visibility state of the addin (i.e. whether the containing slide is currently visible on screen).

文档建议 没有专门用于此目的的API,所以我一直在使用 以下方法:

The documentation suggests no API specifically intended for this purpose, so I've been using the following method:

  1. 在插件初始化之后(在Document.initialize回调内部), 使用Document.getSelectedDataAsync请求当前选择的幻灯片 方法.
  2. 由于addin直到可见后才能初始化,因此我们几乎可以 确保在步骤1中获得的索引是包含幻灯片之一 (除非用户足够快地在 getSelectedDataAsync正在进行异步通信.
  1. Upon addin initialization (inside Document.initialize callback), request currently selected slide using Document.getSelectedDataAsync method.
  2. Since addin cannot be initialized until it is visible, we can be almost sure that the index obtained in the step 1 is the one of the containing slide (unless the user was fast enough to change the slide while getSelectedDataAsync was doing its async communication).

但是,步骤2中的假设已被证明是错误的.它拥有 适用于PowerPoint Online,但台式机PowerPoint的行为有所不同.

However, the assumption made in the step 2 has proved to be wrong. It holds for PowerPoint Online, but desktop PowerPoint behaves differently.

特别是在幻灯片放映模式下,如果当前显示的幻灯片旁边的幻灯片 包含一个插件,并且该插件尚未初始化,因此已被预先初始化 尽管它是不可见/活动的.并且在所有这样的预初始化中 插件,Document.getSelectedDataAsync返回当前幻灯片的索引 显示出来的,而不是包含该插件的信息.

Specifically, in slide show mode, if the slide next to the currently displayed one contains an addin, and that addin is not yet initialized, it gets pre-initialized despite the fact that it is not visible/active. And in all such pre-initialized addins, Document.getSelectedDataAsync returns the index of the slide that is currently displayed, which is not the one that contains the addin.

因此,问题是:有没有一种方法可以或多或少地可靠地确定包含 幻灯片索引,可以同时在Web和桌面版本的PowerPoint中使用?

So the question is: is there a way to more or less reliably determine the containing slide index, the way that works in both web and desktop versions of PowerPoint?

如果否,这是第二个问题:是否可以通过外接程序确定包含幻灯片的幻灯片当前是否在幻灯片放映模式下显示在屏幕上?

If no, here's the second question: is there a way for an addin to determine whether the containing slide is currently visible on screen in slide show mode?

我找到了一个可以在PowerPoint Online中使用的工具(在 幻灯片放映模式),但它依赖于内部实现细节 随时可能更改,最关键的是,它在台式机上不起作用 PowerPoint.

I've found one that works in PowerPoint Online (checking window.innerHeight in slide show mode), but it relies on internal implementation details that are subject to change any time, and, most critically, it doesn't work in desktop PowerPoint.

Desktop PowerPoint似乎在单独的窗口中显示每个插件(如 window.parent等于window),但我找不到一个API或解决方法 将允许告诉窗口当前是否可见. 页面可见性API 似乎完全符合此目的,甚至已在IE11中实现,但 在PowerPoint中不起作用(visibilitychange事件不会触发, document.visibilityState始终等于"visible",即使加载项为 在当前隐藏的幻灯片上.

Desktop PowerPoint seems to display each addin in a separate window (as window.parent equals window), and I failed to find an API or workaround that would allow to tell whether the window is currently visible. Page Visibility API seems to fit this purpose perfectly, and it is even implemented in IE11, but it doesn't work inside PowerPoint (visibilitychange events don't fire, document.visibilityState always equal "visible", even if the addin is on a currently hidden slide).

推荐答案

当前,PowerPoint客户端似乎返回活动幻灯片而不是父幻灯片,因为函数"getSelectedDataAsync"是异步的.

At present, the PowerPoint client seems return the active slide instead of the parent slide since the function "getSelectedDataAsync" is asynchronous.

是否有一种或多或少可靠地确定包含幻灯片的索引的方法,这种方法在PowerPoint的Web和桌面版本中均可使用?

is there a way to more or less reliably determine the containing slide index, the way that works in both web and desktop versions of PowerPoint?

据我所知,没有API返回包含内容应用程序的幻灯片.而且,如果您希望Office加载项支持此API,则可以从此处提交反馈.

As far as I know, there is no API to return the slide which contains the content app. And if you want the Office add-in support this API, you can submit the feedback from here.

这篇关于获取PowerPoint内容加载项(Office.js)的幻灯片索引或可见性状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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