Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Home.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. (function () {
  2. "use strict";
  3. var messageBanner;
  4. // 每次載入新的頁面時,都必須執行 initialize 函式
  5. Office.initialize = function (reason) {
  6. $(document).ready(function () {
  7. var element = document.querySelector('.ms-MessageBanner');
  8. messageBanner = new fabric.MessageBanner(element);
  9. messageBanner.hideBanner();
  10. $('#get-data-from-selection').click(getDataFromSelection);
  11. });
  12. };
  13. // 從目前文件選取範圍讀取資料並顯示通知
  14. function getDataFromSelection() {
  15. if (Office.context.document.getSelectedDataAsync) {
  16. Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
  17. function (result) {
  18. if (result.status === Office.AsyncResultStatus.Succeeded) {
  19. showNotification('選取的文字為:', '"' + result.value + '"');
  20. } else {
  21. showNotification('錯誤:', result.error.message);
  22. }
  23. }
  24. );
  25. } else {
  26. app.showNotification('錯誤:', '這個主應用程式不支援讀取選取項目資料。');
  27. }
  28. }
  29. // Helper 函式,用於顯示通知
  30. function showNotification(header, content) {
  31. $("#notificationHeader").text(header);
  32. $("#notificationBody").text(content);
  33. messageBanner.showBanner();
  34. messageBanner.toggleExpansion();
  35. }
  36. })();