Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

office365 - Get slide index or visibility state of PowerPoint content addin (Office.js)

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).

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

  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).

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

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.

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?

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 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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...