【问题标题】:Is there a slide transition event for PowerPoint add-in (apps)PowerPoint 加载项(应用程序)是否有幻灯片转换事件
【发布时间】:2015-07-31 01:01:00
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: add-in office-addins powerpoint-2013


    【解决方案1】:

    没有直接的方法可以做到这一点。 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);
    

    【讨论】:

    • 嗨!是否有计划为幻灯片更改事件添加回调支持?看起来马丁不是唯一需要这个的人)))
    • 既然是 3 年前的了,有没有添加这个幻灯片更改事件?
    • 我正在拼命寻找一个解决方案,这个解决方案可以做到这一点,但它实际上只在“编辑”模式下有效,一旦在“读取”模式下,我在控制台中遇到错误。幻灯片开始后是否有解决方法?编辑:我的错,当您减少幻灯片控制器以尝试观看后面的调试控制台时,它工作完美除了,它在其他情况下工作正常。
    • 太好了,很高兴这个答案仍然提供一些价值。
    • 由于 PowerPoint 桌面使用 Internet Explorer 作为内部浏览器,getSelectedDataAsync 会引发内存泄漏。任何替代解决方案?
    猜你喜欢
    • 2012-09-15
    • 2012-09-14
    • 2020-05-11
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 2021-01-21
    • 2011-03-01
    相关资源
    最近更新 更多