0

我是 Office 应用程序开发的新手。我想在按钮单击时为选定的文本添加评论。我可以使用以下代码获取选定的文本,但我不知道如何在选定的文本中添加注释。

代码: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);
                }
            }
        );
    }
})();

不锈钢: 在此处输入图像描述

有人可以指导我在所选文本中添加评论吗?

4

1 回答 1

0

我可以将setSelectedDataAsync方法与选项一起使用。 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);
    }
});
于 2017-04-13T14:17:54.483 回答