(function () { "use strict"; var messageBanner; // 每次載入新的頁面時,都必須執行 initialize 函式 Office.initialize = function (reason) { $(document).ready(function () { var element = document.querySelector('.ms-MessageBanner'); messageBanner = new fabric.MessageBanner(element); messageBanner.hideBanner(); $('#get-data-from-selection').click(getDataFromSelection); }); }; // 從目前文件選取範圍讀取資料並顯示通知 function getDataFromSelection() { if (Office.context.document.getSelectedDataAsync) { Office.context.document.getSelectedDataAsync(Office.CoercionType.Text, function (result) { if (result.status === Office.AsyncResultStatus.Succeeded) { showNotification('選取的文字為:', '"' + result.value + '"'); } else { showNotification('錯誤:', result.error.message); } } ); } else { app.showNotification('錯誤:', '這個主應用程式不支援讀取選取項目資料。'); } } // Helper 函式,用於顯示通知 function showNotification(header, content) { $("#notificationHeader").text(header); $("#notificationBody").text(content); messageBanner.showBanner(); messageBanner.toggleExpansion(); } })();