如何从 Office 加载项获取 SharePoint O365 文档 ID

How to get the SharePoint O365 document ID from an Office Add-in

我有一个托管在 SharePoint Online 中的自定义 PowerPoint Office 加载项。我正在使用 JavaScript API 获取有关幻灯片的信息,例如当前幻灯片 ID。

Office.initialize = function (reason) {
  $(document).ready(function () {
    Office.context.document.addHandlerAsync('documentSelectionChanged', onDocumentSelectionChanged);
      onDocumentSelectionChanged();
    });
};

function onDocumentSelectionChanged() {
  Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange,
    function (result) {
      if (result.status === Office.AsyncResultStatus.Succeeded) {
        var slideId = result.value.slides[0].id;
      }
  });
}

我在 API 中找不到任何东西来获取当前 SharePoint 文档的 ID (guid)。这是办公室的一部分 API 还是我可以通过其他方式获得 ID?

你不能只从 SourceDoc 查询字符串中得到它吗属性?

您过去可以将 SourceDoc 作为必需的标记参数传递给插件。现在他们已将其作为 json 字符串移至 window.name。所以你需要做 JSON.parse(window.name).xdmInfo 和一些额外的字符串操作来清理 URL。它包含共享点 url 和共享点内文档的 GUID