0

I'm looking to collect all of the text that is on a slide using the new office-js APIs obviously focusing on the powerpoint API here. The data I'm looking for is all the way down in: context.presentation.slides.getItemAt(0).shapes.items.TextFrame.TextRange.text - and I haven't been able to successfully retrieve that data with all of the loads and context syncing necessary. I've tried:

  • Loading shapes and loading shapes.items, throws an error
  • Loading shapes and parsing through shapes.items, is an empty array
  • Doing the below, which suggests textframe doesn't exist as an attribute

async function getText() {
            await PowerPoint.run(async (context) => {

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

                // Queue a command to load the pages.           
                shapes2.load({ "select": "TextFrame", "top": 5, "skip": 0 });
                return context.sync()
                    .then(function () {
                        // Iterate through the collection of pages.    
                        $.each(shapes2.items, function (index, shape) {
                            // Show some properties.
                            console.log("Page title: " + JSON.stringify(shape.TextFrame));
                        });
                    }).catch(function (error) {
                        console.log("Error: " + error);
                        if (error instanceof OfficeExtension.Error) {
                            console.log("Debug info: " + JSON.stringify(error.debugInfo));
                        }
                    })
            });
        }

I'm doing this all in a functionFile in a ppt extension.

I'm aware this API is in beta but nonetheless this feels like functionality that should be simple to figure out. Any thoughts on the correct approach?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45

0 Answers0