【问题标题】:Office Add-in: Saving Custom Document Properties with Office js in WindowsOffice 插件:在 Windows 中使用 Office js 保存自定义文档属性
【发布时间】:2018-07-24 04:09:15
【问题描述】:

背景:

我正在 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 自己提供的以下 repo 的帮助,office-js-snippets

问题:

我无法在 windows 的机器上运行我的代码。调试完代码后发现我的代码卡在了这个点:await context.sync();

办公版本:

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> 没什么……

【问题讨论】:

    标签: office-js office-addins excel-addins word-addins


    【解决方案1】:

    我最好的猜测是,这与异步/等待(不)在 IE11 上的工作方式有关,并且您必须添加正确的 polyfill 来处理此问题。

    【讨论】:

    • 这是一个很好的观点。让我检查一下。请同时查看我更新的帖子。
    • 事实证明,Async/Await 在 IE 11 上运行良好。因为我在 IE 11 上单独测试了我的代码。所以我认为问题在于读取文档属性。由于某些原因,Office API 不允许从 context.document.properties.customProperties 读取 items 属性。
    • 如果更新权限后一切正常,但我仍然认为这是一个错误,因为我希望在具有相同权限集的 Mac 和 Windows 版本的 Office 上出现相同的行为。如果您具有读取权限,则应该只读取属性并在写入时获得拒绝权限。如果您确定是这种情况并且您可以抽出 10 分钟时间,请前往 github.com/OfficeDev/office-js/issues 开票,您可能会帮助面临同样问题的其他人。
    • 已创建问题here
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多