contentControl

时间:2016-02-06 00:57:25

标签: ms-office office-js word-addins

在Word 2016的Office API中我使用contentControl的insertHtml函数来插入html格式的文本。文本作为块元素插入,并在末尾添加额外的行。 API for Word 2013中的类似功能,setDataAsync与coercionType" html"正确工作并插入内联元素。有没有办法指定我需要一个内联元素。

我尝试插入(text <i>inserted</i> with <b>insertHtml</b>)时基本上需要的是:

  

这是现有文字(文字插入 insertHtml )后跟   更多文字

我得到的是:

  

这是现有文字

     

(文字插入 insertHtml

     

&LT;空行&gt;

     

后面跟着更多文字

谢谢。

1 个答案:

答案 0 :(得分:0)

这是Word JavaScript API的一个已知问题,我们正在努力修复它。在此期间,请使用带有coercionType HTML的setSelectedDataAsync来实现您的需求。 insertHtml将具有相同的行为。

这里是一些代码示例,用于添加问题的上下文。基本上打算抓住当前选择并插入一些HTML。在API中有两种方法(见下文)。现在,insertHtml在末尾添加了一个段落标记,这是我们即将修复的错误。

function insertHtmlSample() {
    Word.run(function (context) {
        var mySelection = context.document.getSelection();
        mySelection.insertHtml("text <i>inserted</i> with <b>insertHtml</b>", "before");
        return  context.sync();

    }).catch(function (error) {
        app.showNotification(error.message);
    })
}


function InsertHtmlOld() {
    Office.context.document.setSelectedDataAsync("text <i>inserted</i> <p> with </p> <b>insert  <p>Html</b> </p> Hello!!!  ", { coercionType: 'html' });
}
相关问题