Search code examples
powerpointoffice-jsoffice-addinsjavascript-api-for-officepowerpoint-web-addins

OfficeJS Extracting all shape from every slide of a PowerPoint document


We want to extract all shape of an opened PowerPoint document from an add-in.

We haven't found much documentation on how to use the API for PowerPoint specifically (this is all we found). We did able to get the selected shape data from the slide with .getSelectedShapes() but we need get shapes from entire presentation.

How might we best approach this?


Solution

  • You can use the following sequence of calls to get all shapes for a slide:

    const shapes = context.presentation.slides.getItemAt(0).shapes;
    

    For example, the following code shows how to delete shapes:

    await PowerPoint.run(async (context) => {
        // Delete all shapes from the first slide.
        const sheet = context.presentation.slides.getItemAt(0);
        const shapes = sheet.shapes;
    
        // Load all the shapes in the collection without loading their properties.
        shapes.load("items/$none");
        await context.sync();
            
        shapes.items.forEach(function (shape) {
            shape.delete();
        });
        await context.sync();
    });
    

    See Work with shapes using the PowerPoint JavaScript API for more information.