Javascript 如何使用Office App向MS Word中的选定文本添加注释?
我是Office应用程序开发新手。我想在单击按钮时向所选文本添加注释。我可以使用下面的代码获取所选文本,但我不知道如何在所选文本中添加注释 代码:Home.jsJavascript 如何使用Office App向MS Word中的选定文本添加注释?,javascript,office365api,office365-apps,office365-restapi,office-app,Javascript,Office365api,Office365 Apps,Office365 Restapi,Office App,我是Office应用程序开发新手。我想在单击按钮时向所选文本添加注释。我可以使用下面的代码获取所选文本,但我不知道如何在所选文本中添加注释 代码:Home.js (function () { "use strict"; // The initialize function must be run each time a new page is loaded Office.initialize = function (reason) { $(documen
(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:
有人能指导我在所选文本中添加评论吗?我可以使用带有选项的方法。
非常感谢你。我一定会试试这个。如果这个解决方案有效的话,那就太好了。我可以添加HTML格式的评论吗?i、 你好,世界!应以粗体添加注释。
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);
}
});