0

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://learn.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));
})

2 Answers 2

3

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");
}
Sign up to request clarification or add additional context in comments.

1 Comment

No need to load all the properties of all the slides as we are only interested in the slide count, which is obtain via a getter (which is not a property). You can safely drop context.presentation.load("slides"); await context.sync();
0
PowerPoint.run(async function (context) {
  context.presentation.load("slides");
  await context.sync();
  const slide = context.presentation.slides.getItemAt(0);
  slide.load("id");//you just load any property from PPT object model and then sync
  await context.sync();
  console.log(slide.id);
});

2 Comments

Please explain your solution. Answers which do not have an explanation and are only code get flagged as low effort
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.