Office.js 尝试在选择处插入 ContentControl 时抛出 GeneralException 异常

Office.js throws GeneralException exception when tried to insertContentControl at the selection

我正在使用 office.js 为 ms word 开发一个插件,但是当我尝试在 范围内像这样 link 调用 range.insertContentConrol() 时出现错误word文档选择range.This是我的代码:

function insertContentControl(outPutText) {
    // Run a batch operation against the Word object model.
    Word.run(function (context) { 
        //context.document.body.insertText("test", "");
        // Create a proxy range object for the current selection. 
        var range = context.document.getSelection();
        // Queue a commmand to create the content control.
        var myContentControl = range.insertContentControl();
        myContentControl.tag = outPutText;
        myContentControl.title = 'test';
        //myContentControl.style = 'Heading 2';
        myContentControl.insertText(outPutText, 'replace');
        myContentControl.cannotEdit = true;
        return context.sync(); 
    })
    .catch(function (error) {
        //console.log('Error: ' + JSON.stringify(error));
        if (error instanceof OfficeExtension.Error) {
            //console.log('Debug info: ' + JSON.stringify(error.debugInfo));
        }
    });
 }

outPutText值可能是“[1]”是通过其他函数返回得到的。

好的,经过一番讨论,问题是使用了来自 office.js 的陈旧副本(在下载示例时)。解决方案是始终从我们的 CDN 获取 office.js。 (https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js)