2016-04-28 360 views
2

我通過以下鏈接試圖displayDialogAsync方法, https://channel9.msdn.com/Shows/Office-Dev-Show/Office-Dev-Show-Episode-26-Using-the-Dialog-API-in-Office-Add-ins 當我測試從GitHub的項目,我在Office.context.ui得到一個錯誤「權限被拒絕的錯誤」。 displayDialogAsync。 下面是一個簡單的代碼:Office.context.ui.displayDialogAsync權限被拒絕的錯誤

function ShowDialog() { 
 
     // Reference the Form.html file. 
 
     var dialogUrl = 'https://' + location.host + '/Form.html'; 
 
     // Display the dialog. 
 
     Office.context.ui.displayDialogAsync(dialogUrl, { width: 15, height: 27, requireHTTPS: true }, function (asyncResult) { 
 
      if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) { 
 
       // TODO: Handle error. 
 
       return; 
 
      } 
 

 
      // Get the dialog and register event handlers. 
 
      var dialog = asyncResult.value; 
 
      dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, function (asyncResult) { 
 
       if (asyncResult.type !== Microsoft.Office.WebExtension.EventType.DialogMessageReceived) { 
 
        // TODO: Handle unknown message. 
 
        return; 
 
       } 
 

 
       // Parse the message. 
 
       var data = JSON.parse(asyncResult.message); 
 
       showNotification('Hello #Office365Dev', data.name); 
 

 
       // TODO: Do something with the data. 
 

 
       // We got our data, time to close the dialog. 
 
       dialog.close(); 
 
      }); 
 
     }); 
 
    }

感謝您的幫助。

回答

2

根據給出的信息,不清楚您運行的是哪個Office應用程序,您正在運行的是哪個版本的Office,也不知道您正在加載哪個版本的Office.js。

對話框API僅適用於最新的點擊運行Office 365版本(6741之後)和最新的Mac版本。確保您使用的是最新版本的Office。對話框API在所有應用程序中都不可用,但它應該在Excel,Word和PowerPoint的Office.js 1.1中正確加載。 Outlook的情況略有不同。該Office的Office Online應用程序版本仍在開發中。

API文檔在線:https://github.com/OfficeDev/office-js-docs/blob/master/reference/shared/officeui.md

+0

感謝您的幫助。我使用Office 2016 msi版本進行了測試,我將嘗試檢查它是否適用於點擊運行版本。 –

+0

對於MSI版本,API應在May更新中可用。 –