发布
社区首页 >问答首页 >PowerPoint Javascript API获取演示文稿的幻灯片属性

PowerPoint Javascript API获取演示文稿的幻灯片属性
EN

Stack Overflow用户
提问于 2021-01-08 14:39:40
回答 2查看 113关注 0票数 1

我已经尝试了很多方法来实现这一点,但是我不能仅仅使用我尝试过的代码来获得PowerPoint.SlideCollection或PowerPoint.Slide。文档中没有关于这一点的示例。我可以在PowerPoint.run()中编写哪些代码片段来获取幻灯片(PowerPoint.SlideCollection)或特定的幻灯片PowerPoint.Slide?

下面是我写的代码:

代码语言:javascript
代码运行次数:0
复制
function log(str) { document.getElementById('log').textContent += '\n[LOG]' + str; }
function logObject(obj) { log(JSON.stringify(obj)); }

Office.onReady(info => {
  if(info.host === Office.HostType.PowerPoint) {

    OfficeExtension.config.extendedErrorLogging = true;
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = getSlideCollection;
  }
});

async function getSlideCollection() {
   await PowerPoint.run(async function(context) {
      let slides =  context.presentation.slides;
      await context.sync().then((res)=>{
        logObject(res);
      }).catch((err)=>{
        logObject(err);
      });
     
  });
}

我得到的错误是:

代码语言:javascript
代码运行次数:0
复制
{"name":"RichApi.Error","code":"GeneralException","traceMessages":[],"innerError":null,"debugInfo":{"code":"GeneralException","message":"GeneralException","errorLocation":"Presentation.slides","statement":"var slides = root.slides;","surroundingStatements":["var root = context.root;","// >>>>>","var slides = root.slides;","// <<<<<"],"fullStatements":["var root = context.root;","var slides = root.slides;"]},"httpStatusCode":500}
EN

回答 2

Stack Overflow用户

发布于 2021-01-08 16:47:02

下面是一个简单的代码片段,可以帮助您:

代码语言:javascript
代码运行次数:0
复制
function GetSlideCollection() {
    await PowerPoint.run(async function(context) {
        let slides =  context.presentation.slides;
        await context.sync();
    });
}
票数 1
EN

Stack Overflow用户

发布于 2021-01-14 03:33:57

由于.slides是一个beta feature (在预览中),您应该导入预览API js文件(You can refer this document)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65624469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档