I am developing a word add-in using word JavaScript api, I need to insert some data in table format inside the content Control and placed that content control on top of document. Please advice.
Thanks.
I am developing a word add-in using word JavaScript api, I need to insert some data in table format inside the content Control and placed that content control on top of document. Please advice.
Thanks.
这应该是一个相当简单的操作。我假设文档的“顶部”是指在文档开始的地方插入一个表格。第一行。
所有插入方法都有一个可以用于该目的的插入位置参数。在这种情况下,您要做一个 body.isnertTable,第三个参数是 insertLocation(“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);
})
}