0
votes

I am trying to use the new Office.js API for Powerpoint which is currently in preview. I am unable to get anything working with the PowerPoint.run() method call because it seems to behave differently that the ones in Excel and Word. Could anyone help me find a working way to call the SlideCollection.getCount() method referenced here?

https://docs.microsoft.com/en-us/javascript/api/powerpoint/powerpoint.slidecollection?view=powerpoint-js-preview

Sample code (assumed I needed to load items first before trying to get the count):

PowerPoint.run(function (context) {
  var properties = context.presentation.slides.items;
  context.load(properties);
  return context.sync()
    .then(function() {
      console.log(properties);
    })
    .catch((error) => console.log(error));
})
1

1 Answers

2
votes

Here is a call to slides.getCount() which should work

PowerPoint.run(async (context) => {
    context.presentation.load("slides");
    await context.sync();

    var slides = context.presentation.slides;
    var slideCount = slides.getCount();
    await context.sync();

    console.log("There are ", slideCount.value, " slides in this presentation");
}