Office 加载项:在 Windows 中使用 Office js 保存自定义文档属性

Office Add-in: Saving Custom Document Properties with Office js in Windows

背景:

我正在 macOS 中开发一个插件,我能够阅读自定义文档 属性:

return await this.api.run(async (context) => {
    const properties = context.document.properties.customProperties;
    properties.load('key,type,value');
    await context.sync();

    const roomID = properties.items.find(item => item.key === 'Webex_Teams_roomID');
    return roomID ? roomID.value : null;
  });

并写一个:

  return await this.api.run(async (context) => {
    context.document.properties.customProperties.add('Webex_Teams_roomID', newRoomID);
    await context.sync();
  });

其中 this.api 只是 window.word 使用 office JS API。我使用了 Microsoft 自己提供的以下存储库的帮助,office-js-snippets.

问题:

我无法在 window 的机器上 运行 我的代码。调试代码后,我了解到我的代码卡在了这一点:await context.sync();.

Office 版本:

macOS 中的 Office 版本:16.14.1 (180613)

Windows 中的 Office 版本:16.0.4639.1000 32-bit

更新:

经过一番挖掘,我发现我无法访问 context.document.properties.customProperties.items。它将显示 <permission denied> 错误。难道是这个?

然后我将 Permissions 设置为 ReadWriteDocument <Permissions>ReadWriteDocument</Permissions> 没什么....

我最好的猜测是,这与 async/await(不)在 IE11 上的工作方式有关,您必须添加正确的 polyfill 来处理这个问题。

事实证明,这个 MSI 版本和我正在使用的 API 存在一些不兼容问题,这些问题导致了我之前遇到的问题。他们建议我转到 365。