3

我正在为 PowerPoint 开发 Office 加载项。这是 Office 商店的现代“加载项”,而不是旧式加载项。

有没有办法在活动幻灯片更改时得到通知?

我的情况是,当幻灯片随着演示文稿而改变时,我想在我的加载项代码中做一些事情。

在这个阶段,我的应用程序可能是内容或任务窗格应用程序。

4

1 回答 1

3

没有直接的方法可以做到这一点。Office JS 库在 PowerPoint 中没有幻灯片转换事件。

但是,有一种方法可以做到这一点,它涉及定期刷新 Web 应用程序并将 getSelectedDataAsync 与 SlideRange 的 CoercionType 一起使用。这为您提供了文档中的全部幻灯片,您可以从中获取当前幻灯片的索引。您可以将该索引存储在一个设置中,并检查它是否会更改,如果您有您的事件。

这是基本代码(每 1.5 秒刷新一次)

//Automatically refresh
window.setInterval(function () {
//get the current slide
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (r) {

      // null check
      if (!r || !r.value || !r.value.slides) {
        return;
      }

    //get current slides index
    currentSlide = r.value.slides[0].index;

    //get stored setting for current slide
    var storedSlideIndex = Office.context.document.settings.get("CurrentSlide");
    //check if current slide and stored setting are the same
    if (currentSlide != storedSlideIndex) {
        //the slide changed - do something
        //update the stored setting for current slide
        Office.context.document.settings.set("CurrentSlide", currentSlide);
        Office.context.document.settings.saveAsync(function (asyncResult) { });
    }

});

}, 1500);
于 2015-08-07T06:32:34.240 回答