Office js API setDataAsync 未按照文档中的建议工作

Office js API setDataAsync not working as suggested in Document

我正在开发一个词添加,其中有用于在 Binding.My 中插入富文本格式的用例绑定类型是 'Text' 并且我还将 coercionType 设置为 'Html' 仍然不是在 binding.My 主机应用程序中替换为 word online.Whereas,这是在 word 桌面 application.But 中工作的,我想在 word online 中使用它。 请建议。 谢谢

    /*
    *addBindingToData
    *@param userSelectedText -- is a string selected in word document
    */
    function addBindingToData(userSelectedText) {
        var bindVariableIdPrefix = userSelectedText + '_Binding';
        Office.context.document.bindings.addFromSelectionAsync(Office.BindingType.Text, {
            id: bindVariableIdPrefix + '__' + count
        }, function(asyncResult) {
            if (asyncResult.status == Office.AsyncResultStatus.Failed) {
                console.log('Action failed. Error: ' + asyncResult.error.message);
            } else {
                console.log('Added new binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
                getVarArrayOnSelection(asyncResult.value.id,userSelectedText, bindVariableIdPrefix).then(function(bindings) {
                    createInputboxes(bindings);
                });
            }
        });
        count++;
    }
Office.context.document.bindings.getByIdAsync(obj.id,function(asyncResult) {
            if (asyncResult.status == Office.AsyncResultStatus.Failed) {
                console.log('Action failed. Error: ' + asyncResult.error.message);
            } else {
                console.log(asyncResult.value.id+'got Id');
                var BindingId = asyncResult.value;
                BindingId.setDataAsync("<b>Hello</b> World!", {coercionType: "html"}, function (asyncResult) {
                    if (asyncResult.status == "failed") {
                        console.log('Error: ' + asyncResult.error.message);
                    }
                });
            }

        });

Picture of problem
One Drive Picture

经过进一步调查,我能够重现此问题并了解根本原因。

长话短说:当在文档中创建绑定时,实际上发生的是将新的内容控件添加到文档中。根据创建绑定时用户的选择,创建一种类型的内容控件,它可以是:

  1. BLOCK 内容控件:如果选择包括一个或多个完整段落,则会创建 BLOCK 内容控件。在这种情况下,HTML 插入成功(这是我正在尝试的)。

    1. INLINE content Control: 另一方面,如果选择是部分选择(在一个段落内,没有完全选择它)那么 INLINE 内容控件已创建。在这种情况下,HTML 插入失败。

好消息是这是一个已知问题,我们正在努力在不久的将来启用它。

原答案留作参考。 谢谢! =================原始答案============================

我在 Word Online 中尝试了您的代码但是我无法重现这个问题。我可以看到文档中正确打印了 HTML。

有几个问题:

  1. 能否添加您用于创建绑定的代码?
  2. 您是否也在 OneDrive for consumer 或 OneDrive for Business 中尝试过此操作。这对更详细地调查非常有帮助。

谢谢! 娟.