Issue: Microsoft PowerPoint API returns empty placeholder text after update [2409]

Nambi N. Rajan 0 Reputation points
2024-11-05T08:02:10.62+00:00

I’m using the Microsoft PowerPoint JavaScript API to generate slides from slide master, where the shapes are created within layouts using GeometricShape. A placeholder text is assigned to each shape to help identify them, so they can later be populated with the correct data.

This code functioned correctly with an earlier version of Office (Version 2409, Build 18025.20160). However, since a recent Office update, it now returns an empty string for the placeholder text, despite previously working without any issues.

Here’s the code that was used to access slide masters, layouts, and shapes within a PowerPoint presentation:

$("#run").on("click", run);

async function run() {
  await PowerPoint.run(async (context) => {
    context.presentation.load("slideMasters");
    await context.sync();
    const slideMasters = context.presentation.slideMasters;
    const validSlideMasters = await getAllSlideMasterInList(slideMasters);
    for (const master of validSlideMasters) {
      master.load();
      await context.sync();
      const validLayoutArray = await getValidSlideLayoutsFromSlideMaster(master);
      for (const layout of validLayoutArray) {
        await getSlideLayoutPlaceholderText(layout);
      }
    }
  });
}

async function getAllSlideMasterInList(slideMasterCollection) {
  const slideMasterList = [];
  const context = slideMasterCollection.context;
  slideMasterCollection.load("items");
  await context.sync();
  slideMasterCollection.items.forEach((slideMaster) => {
    slideMasterList.push(slideMaster);
  });
  return slideMasterList;
}

async function getValidSlideLayoutsFromSlideMaster(slideMaster) {
  const slideLayoutArray = [];
  const context = slideMaster.context;
  slideMaster.load("layouts");
  slideMaster.load("name");
  await context.sync();
  const slideLayouts = slideMaster.layouts;
  slideLayouts.load("items");
  await context.sync();
  slideLayouts.items.forEach((slideLayout) => {
    if (slideLayout.name.startsWith("TestLayoutName")) {
      slideLayoutArray.push(slideLayout);
    }
  });
  return slideLayoutArray;
}

async function getSlideLayoutPlaceholderText(slideLayout) {
  const context = slideLayout.context;
  slideLayout.load("shapes");
  slideLayout.load("name");
  await context.sync();
  const shapes = slideLayout.shapes;
  shapes.load("items");
  await context.sync();
  for (const shape of shapes.items) {
    if (shape.type === "GeometricShape") {
      shape.load();
      shape.textFrame.load();
      await context.sync();
      shape.textFrame.textRange.load(["text"]);
      await context.sync();
      console.log("Slide Layout Name:", slideLayout.name);
      console.log("Shape text", shape.textFrame.textRange.text);
    }
  }
}

Here is the sample slide master view: (https://i.sstatic.net/9nqllwuK.png)

Issue Observed: Previously, shape.textFrame.textRange.text would return the text of placeholders and shapes, as expected. However, since the recent update, shape.textFrame.textRange.text is now returning an empty string for placeholders that previously had text.

Troubleshooting Attempts:

  1. Verified that placeholders in the PowerPoint presentation have text.
  2. Checked that the textFrame and textRange objects are properly loaded and synced.
  3. Confirmed that no errors are thrown by the API.

Environment:

  • Previous Office Version: Version 2409 (Build 18025.20160) - working as expected
  • Current Office Version: Version 2410 (Build 18129.20116) - issue observed

Question: Has anyone experienced similar issues with placeholder text retrieval after a recent Office update? Is there any workaround, or has something changed in the API that might be causing this behavior? Any insights would be appreciated.

PowerPoint
PowerPoint
A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
309 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,002 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,015 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.