0

Ich bin neu in Office App Entwicklung. Ich möchte einen Kommentar zum ausgewählten Text beim Klicken auf die Schaltfläche hinzufügen. Ich kann ausgewählten Text mit dem folgenden Code abrufen, aber ich weiß nicht, wie Sie einen Kommentar im ausgewählten Text hinzufügen können.Wie man Kommentar zum ausgewählten Text in MS Word mit Office App hinzufügen?

Code: Home.js

(function() { 
    "use strict"; 

    // The initialize function must be run each time a new page is loaded 
    Office.initialize = function (reason) { 
     $(document).ready(function() { 
      app.initialize(); 

      $('#get-data-from-selection').click(getDataFromSelection); 
     }); 
    }; 

    // Reads data from current document selection and displays a notification 
    function getDataFromSelection() { 
     Office.context.document.getSelectedDataAsync(Office.CoercionType.Text, 
      function (result) { 
       if (result.status === Office.AsyncResultStatus.Succeeded) { 
        app.showNotification('The selected text is:', '"' + result.value + '"'); 
       } else { 
        app.showNotification('Error:', result.error.message); 
       } 
      } 
     ); 
    } 
})(); 

SS: enter image description here

Kann jemand bitte leite über mich Kommentar in ausgewählten Text hinzufügen?

Antwort

0

Ich kann die setSelectedDataAsync Methode mit den Optionen verwenden. https://dev.office.com/reference/add-ins/shared/customxmlnodetype-enumeration

Office.context.document.setSelectedDataAsync("my comment", {CustomXMLNodeType: Office.Office.CustomXMLNodeType.NodeComment} 
function (asyncResult) { 
    var error = asyncResult.error; 
    if (asyncResult.status === Office.AsyncResultStatus.Failed){ 
     console.log(error.name + ": " + error.message); 
    } 
}); 
+0

Vielen Dank. Ich werde es sicherlich versuchen. Das wird wirklich toll, wenn diese Lösung funktioniert. Kann ich Kommentare im HTML-Format hinzufügen? d. h. Hallo Welt! sollte Kommentar in Fettdruck hinzufügen. –

Verwandte Themen