PowerPoint JS API: insert an image and set the title at the same time

495 Views Asked by At

I am using Script Lab to build my add-in for PowerPoint on the web. I want to insert some images and encode extra information for each image in the title. The information I want to store depends on the content of the images.

From the example provided by Script Lab, I can insert images by calling setSelectedDataAsync(data, options, callback) . However, this API doesn't provide any option to set the title of the image.

I have a workaround. After inserting the image with setSelectedDataAsync(data, options, callback) , the inserted image will be selected. I use

PowerPoint.run(
  async (context) => {
    const selected = context.presentation.getSelectedShapes();
    /* do something */
  }
);

to query the selected image and modify the title. The problem with this workaround is there is a time gap between insertion and the query of selected images. My users may do some actions to interrupt the whole process. Additionally, getSelectedShapes() is quite slow when there are many pages or shapes in the slides.

Is there a way to insert and set the title of it at the same time?

1

There are 1 best solutions below

0
On

There is no way to set a title when images are inserted in Office JavaScript API. As a possible workaround, you may consider displaying a progress dialog box to a user to prevent them from editing something on the page.

You can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.