2017-04-10 62 views
0

根據Microsoft's documentation,當用戶通過指定激活規則進入「撰寫」模式時,您應該能夠激活Outlook加載項。自動加載並運行Outlook加載項

在我的表現,我有

<Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" /> 

當您從應用程序欄,打開一個任務窗格右側啓動加載這個工程。但是,我希望它在撰寫窗口打開時不會自動啓動,並且不會打開任務窗格。

這可能嗎?如果是這樣,一個人怎麼能做到這一點?

這裏是清單:

<?xml version="1.0" encoding="UTF-8"?> 
    <!--Created:cb85b80c-f585-40ff-8bfc-12ff4d0e34a9--> 
    <OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MailApp"> 
     <Id>dedf4528-4a6e-443b-8763-4ec32c340240</Id> 
     <Version>1.0.0.0</Version> 
     <ProviderName>Contoso, Inc.</ProviderName> 
     <DefaultLocale>en-US</DefaultLocale> 
     <DisplayName DefaultValue="HelloWorld" /> 
     <Description DefaultValue="HelloWorld"/> 
     <Hosts> 
     <Host Name="Mailbox" /> 
     </Hosts> 
     <Requirements> 
     <Sets> 
      <Set Name="MailBox" MinVersion="1.1" /> 
     </Sets> 
     </Requirements> 
     <FormSettings> 
     <Form xsi:type="ItemEdit"> 
      <DesktopSettings> 
      <SourceLocation DefaultValue="https://l.recognizeapp.com:50000/outlook-addin"/> 
      </DesktopSettings> 
     </Form> 
     </FormSettings> 
     <Permissions>ReadWriteItem</Permissions> 
     <Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" /> 
     <DisableEntityHighlighting>false</DisableEntityHighlighting> 
    </OfficeApp> 

這裏是源位置:

<!DOCTYPE html> 
    <html> 
    <head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta charset="utf-8"> 
    <title></title> 
    </head> 

    <body> 

    <style> 
    html, body, #wrapper { 
     min-height: 100%; 
     height: 100%; 
     width: 100%; 
     min-width: 100%; 
    } 

    p { 
     font-family: arial, sans-serif; 
     font-size: 11px; 
     color: #888; 
    } 

    #wrapper { 
     opacity: 0; 
     -webkit-transition: .5s opacity linear; 
     transition: .5s opacity linear; 
    } 

    #wrapper.loaded { 
     opacity: 1; 
    } 

    #wrapper .inner { 
     text-align: center; 
    } 

    .recognize { 
     color: #1568A6; 
     font-weight: 600; 
    } 
    </style> 

    <div id="wrapper" style="display: flex; align-items: center; justify-content: center; height: 100%; min-height: 100%; width: 100%; min-width: 100%"> 
    <div class="inner"> 
     <img src="/assets/icons/outlook-progress.gif" alt="Loading Recognize"> 
     <p>Loading <span class="recognize">Recognize</span></p> 
    </div> 
    </div> 

    <script src="//appsforoffice.microsoft.com/lib/1/hosted/office.js"></script> 
    <%= javascript_include_tag "outlook-load" %> 
    <script> 
    var item; 

    Office.initialize = function() { 
     item = Office.context.mailbox.item; 
     // Checks for the DOM to load using the jQuery ready function. 
     $(document).ready(function() { 
      // After the DOM is loaded, app-specific code can run. 
      // Insert data in the top of the body of the composed 
      // item. 
      prependItemBody(); 
     }); 
    } 

    // Get the body type of the composed item, and prepend data 
    // in the appropriate data type in the item body. 
    function prependItemBody() { 
     item.body.getTypeAsync(
      function (result) { 
       if (result.status == Office.AsyncResultStatus.Failed){ 
        write(asyncResult.error.message); 
       } 
       else { 
        // Successfully got the type of item body. 
        // Prepend data of the appropriate type in body. 
        if (result.value == Office.MailboxEnums.BodyType.Html) { 
         // Body is of HTML type. 
         // Specify HTML in the coercionType parameter 
         // of prependAsync. 
         item.body.prependAsync(
          '<b>Greetings, '+Office.context.mailbox.userProfile.emailAddress+'</b>', 
          { coercionType: Office.CoercionType.Html, 
          asyncContext: { var3: 1, var4: 2 } }, 
          function (asyncResult) { 
           if (asyncResult.status == 
            Office.AsyncResultStatus.Failed){ 
            write(asyncResult.error.message); 
           } 
           else { 
            // Successfully prepended data in item body. 
            // Do whatever appropriate for your scenario, 
            // using the arguments var3 and var4 as applicable. 
           } 
          }); 
        } 
        else { 
         // Body is of text type. 
         item.body.prependAsync(
          'Greetings, '+Office.context.mailbox.userProfile.emailAddress+":", 
          { coercionType: Office.CoercionType.Text, 
           asyncContext: { var3: 1, var4: 2 } }, 
          function (asyncResult) { 
           if (asyncResult.status == 
            Office.AsyncResultStatus.Failed){ 
            write(asyncResult.error.message); 
           } 
           else { 
            // Successfully prepended data in item body. 
            // Do whatever appropriate for your scenario, 
            // using the arguments var3 and var4 as applicable. 
           } 
          }); 
        } 
       } 
      }); 

    } 

    // Writes to a div with id='message' on the page. 
    function write(message){ 
     document.getElementById('message').innerText += message; 
    } 

    </script> 

    </body> 

    </html> 

此代碼是明顯的,從here混搭和here

回答

0
源位置代碼

這可能嗎?如果是這樣,一個人怎麼能做到這一點?

不,這是不可能的。 Office.js API加載項的設計是必需的用戶調用。對於Outlook加載項,您可以使用"pinnable" taskpane功能在用戶從消息切換到消息時保持加載項處於打開狀態,但這與撰寫無關,並且無論如何都必須由用戶在開始時啓動。

+0

當您突出顯示文本時,沒有辦法激活加載項嗎?想知道是否還有其他潛力鉤子鏈接到。 –

+0

@PeterP。 「激活」=使其可供最終用戶使用(顯示按鈕或鏈接到加載項);開始加載項只能通過用戶調用;用戶選擇是否運行加載項。這是Office.js API的設計方法。自動調用加載項(事件驅動調用)適用於COM/VSTO技術。當用戶突出顯示文本時,不會啓動加載項。在同一時間,如果用戶已經啓動了加載項,add-n代碼可能會訪問突出顯示的文本。希望它能澄清答案。 –

+0

很酷,謝謝Slava! –