【问题标题】:How to insert a table inside a contentControl using Word javascript api如何使用 Word javascript api 在 contentControl 中插入表格
【发布时间】:2017-03-20 16:56:28
【问题描述】:

我正在使用 word JavaScript api 开发一个 word 插件,我需要在内容控件中插入一些表格格式的数据,并将该内容控件放在文档顶部。 请指教。

谢谢。

【问题讨论】:

    标签: ms-word office365 office-js word-addins javascript-api-for-office


    【解决方案1】:

    这应该是一个相当简单的操作。我假设文档的“顶部”是指在文档开始的位置插入一个表格。第一行。

    所有插入方法都有一个可以用于该目的的插入位置参数。在这种情况下你想做一个body.isnertTable,第三个参数是insertionLocation(“start”被发送到插入到文档正文的开头)。

    插入后,您实际上可以用内容控件包装它。查看下面的示例以获取详细信息。我包括了其他细节,例如对插入的表格应用内置样式。

    希望这可以解除对您的阻止。谢谢!

    function insertTableAndWrapWithCC() { 
         Word.run(function (context) {
              // We need a 2D array to hold the initial table values
              var data = [["Apple", "Orange", "Pineapple"],["Tokyo","Beijing", "Seattle"]];
              var table = context.document.body.insertTable(3, 3, "start", data);
              table.styleBuiltIn = Word.Style.gridTable5Dark_Accent2;
    //now we insert the content control on the table.
              var myContentControl = table.insertContentControl();
              myContentControl.title = "CC Title";
              return context.sync()
         })
         .catch(function (e) {
         	       console.log(e.message);
                  })
         }

    【讨论】:

    • 感谢您的回复,它按预期工作。表格内容将如何编辑,因为我正在使用标签加载 CC 并希望用新值替换表格内容。请指教。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    相关资源
    最近更新 更多