如何在Word-Addins任务窗格中创建自定义的Add Comment?

问题描述

我正在为Mac的Word创建一个MS-Word加载项,我必须创建一个带有任务窗格的自定义注释部分,因此我创建了一个文本框,并在单击按钮时创建了一个按钮,然后将按钮注释添加到所选内容中文字。

我找到了很多文章,但对我不起作用,因此我在下面附加了示例代码。

HTML文件

    <div class="padding">
            <textarea id="areaDiv"></textarea>
            <button id="addComment">Add Comment</button>
            <div id="errorDiv"></div>
     </div>

**JS File**
Office.onReady(function () {
    // Office is ready
    $(document).ready(function () {
        // The document is ready
        // Use this to check whether the API is supported in the Word client.
        if (Office.context.requirements.isSetSupported('WordApi','1.1')) {
            // Do something that is only available via the new APIs
            $('#addComment').click(addComment);

            $('#supportedVersion').html('This code is using Word 2016 or later.');
        }
        else {
            // Just letting you know that this code will not work with your version of Word.
            $('#supportedVersion').html('This code requires Word 2016 or later.');
        }
    });
});


// Function that writes to a div with id='message' on the page.

function addComment() {
    Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,{ valueFormat: "unformatted",filterType: "all" },function (asyncResult) {
            var error = asyncResult.error;
            if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                write('');
            }
            else {
                var range = asyncResult.value;
                write(range);
            }
        });
}
function onError(error) {
    $('#errorDiv').text(error.name + ' ' + error.code + ': ' + error.message);
}
function write(range) {
    $('#errorDiv').text(range);
    var text = $("#areaDiv").val();
    if (range != null && range != "" && text != null && text != "") {
        $('#errorDiv').text(range + " " + text);
        var document = Office.context.document.properties.comments;
        document.add(range,text);
        $("#areaDiv").val("");
    }
}

这里没有错误,但是存在一个问题,即未对选定的文本设置注释,也不会出现在catch块中。

如果有人对此有所了解,那么对我有很大帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...