You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Office更新后Microsoft PowerPoint API返回空占位符文本求助

近期Office更新后PowerPoint JS API获取占位符文本返回空字符串的问题

我使用Microsoft PowerPoint JavaScript API从幻灯片母版生成幻灯片,在布局内通过GeometricShape创建形状,每个形状都设置了占位符文本用于后续识别和数据填充。

该代码在旧版Office(Version 2409, Build 18025.20160)中运行正常,但升级到新版Office(Version 2410, Build 18129.20116)后,原本能正常获取的占位符文本现在返回空字符串。

相关代码

$("#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);
    }
  }
}

问题现象

之前shape.textFrame.textRange.text可以正常返回占位符和形状的文本,但更新后,原本包含文本的占位符返回空字符串。

已尝试的排查步骤

  • 确认演示文稿中的占位符确实存在文本
  • 检查textFrame和textRange对象已正确加载并完成同步
  • 确认API调用未抛出任何错误

环境信息

  • 旧版Office:Version 2409 (Build 18025.20160) - 运行正常
  • 当前Office:Version 2410 (Build 18129.20116) - 出现问题

有没有人在近期Office更新后遇到类似的占位符文本获取问题?是否有可行的解决办法,或是API有变更导致了这个问题?


内容的提问来源于stack exchange,提问作者Kasturi Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 15:27:17