使用 JavaScript API 在 PowerPoint 插件幻灯片上创建文本框时出现问题

问题描述 投票:0回答:1

我正在尝试创建一个 PowerPoint 插件,并希望在单击按钮时动态创建活动幻灯片上的文本框并设置其格式。我已经做了很多研究和调试,但我不确定为什么我的代码没有创建文本框。我在 VS Code 上使用 PowerPoint JavaScript API 这是我的示例代码

function createDynamicTextBox() {
// Get the active slide
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (result) {
  if (result.status === Office.AsyncResultStatus.Succeeded) {
    // Get the first slide
    var slide = result.value.slides[0];

    // Create a text box
    var textBox = slide.shapes.addTextbox(Office.CoercionType.Text, 100, 100, 200, 50);

    // Set properties of the text box
    textBox.textFrame.textRange.text = "Dynamic Text Box";
    textBox.textFrame.textRange.font.size = 14;

    // You can further customize the properties as needed
  } else {
   console.error("Error getting selected data: " + result.error.message);
  }
});

问题在于在调试时返回“未定义”的形状对象。我想知道是否有可能实现我想要的目标。

office365 office-js office-addins powerpoint-addins powerpoint-web-addins
1个回答
0
投票

当您想要应用更改时,致电

await context.sync();
是有意义的。

请注意,PowerPoint 形状存在一个活跃问题,请参阅 Powerpoint ScriptLab 插入形状、线条和文本框示例在 Web 上不起作用;在桌面上运行良好了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.