Eren Yenigül
Eren Yenigül

Reputation: 31

PowerPoint Javascript API getting slides property of presentation

I have tried many ways to do this, but I can not just get PowerPoint.SlideCollection, or PowerPoint.Slide with any code that I tried. There are no examples about this on the documentation. What code snippet can I write inside PowerPoint.run() to get PowerPoint.SlideCollection(slides) or a particular slide PowerPoint.Slide?

Here is the code I wrote:

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);
      });
     
  });
}

The error I am getting:

{"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}

Upvotes: 1

Views: 633

Answers (2)

LogiStack
LogiStack

Reputation: 1006

You should import preview API js file (You can refer this document) as .slides is a beta feature (in preview).

Upvotes: 1

qinliuMSFT
qinliuMSFT

Reputation: 155

Here's a simple code snippet could help you:

function GetSlideCollection() {
    await PowerPoint.run(async function(context) {
        let slides =  context.presentation.slides;
        await context.sync();
    });
}

Upvotes: 1

Related Questions