如何将图像添加到幻灯片

How to add an image to a slide

我正在开发 PowerPoint 加载项。我想在幻灯片中添加图像。

我将 Angular 框架与 Typescript 一起用于加载项,并使用Yeoman Office 生成器。

这是我在单击按钮时调用的函数。

async addImage() {
    console.log('addImage')
    
    Office.context.document.setSelectedDataAsync("addImage",
      {
        coercionType: Office.CoercionType.Text,
      },
      result => {
        if (result.status === Office.AsyncResultStatus.Failed) {
          console.error(result.error.message);
        }
      }
    );

  }

添加文字。我想替换它,以便它可以添加图像。

经过一番艰苦的搜索,我找到了答案。我必须使用 base64 字符串并将其添加到 PowerPoint 中,如下所示:

async addImage(imgHTML) {
    console.log('addImage')

    Office.context.document.setSelectedDataAsync('addBase64StringHere', 
      { 
        coercionType: Office.CoercionType.Image, 
      },
      result => {
        if (result.status === Office.AsyncResultStatus.Failed) {
          console.error(result.error.message);
        }
      }
    );

  }