0

I have a function that fetches an API, that converts PowerPoint presentations into base64 strings. After getting the response object, I want to insert the slides into the current presentation, specifically after the currently selected slide.

The way I thought of doing it is what the documentation says: get the selected slide ID and use it in the target slide ID option. The documentation introduces a function, getSelectedSlideIndex(), to get the ID of the selected slide, but it throws a Rich API Promise error. Reference: https://learn.microsoft.com/en-us/office/dev/add-ins/powerpoint/add-slides

export async function getImageAsBase64String() {
  // API call that fetches presentations as base64 strings
  // ..
  const results = await response.json();

  await PowerPoint.run(async (context) => {
    const selectedID = await getSelectedSlideIndex();

    context.presentation.insertSlidesFromBase64(results[0].presentations[0], {  
      targetSlideId: selectedID,
    });          
      await context.sync();
  });
}

Is there a specific format for the selected ID? Ideally, I want to select a slide, press a button and the new slides (as base64 strings) are inserted after the selected slide.

3
  • Why are you using the getSelectedSlideIndex method for adding slides instead of the getSelectedSlideID method for inserting slides? See learn.microsoft.com/en-us/office/dev/add-ins/powerpoint/… Commented May 8, 2023 at 18:25
  • That was it. I don't know why it didn't register that I needed the ID not the index. Thank you. A small follow-up: instead of getting the currently selected slide, is there a way to get a slide ID based on text in the slide? Example: I generate a slide with title "Team"; I want to find that specific slide ID, then insert my other slides after it. Commented May 8, 2023 at 19:16
  • That should really be a separate Stack question, but I think you can iterate over all the slides and all the text shapes in each slide till you find the one with "Teams", then select that slide and use getSelectedSlideID. Commented May 9, 2023 at 20:10

1 Answer 1

0

(Turning a comment into an answer)

Use the getSelectedSlideID method for inserting slides as described in Insert slides.

The getSelectedSlideIndex method is for adding slides.

Sign up to request clarification or add additional context in comments.

Comments

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.