I need to insert a contentControl that will contain a table and wrap this ContentControl inside another parent contentControl. Currently contentControl that contain table data inserted correctly but when i tried to get the current selection and inserting the CC, word showing message 'Rich Text control can not inserted around multiple selection'. Please advice how i can insert CC and wrap inside another parent CC. Thanks.
1 Answer
Don't do it on the selection. Get the range of the content control wrapping the table and then insert another wrapper. like this:
function insertTableWrappedBy2CCs() {
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;
var myCC = table.insertContentControl();
myCC.title = "table";
var cc2 = myCC.getRange().insertContentControl();
cc2.title = "parent";
return context.sync()
})
.catch(function (e) {
console.log(e.message);
})
}
thanks!!!
2 Comments
Amit
Thanks, It working to wrap the cc inside another. If i need to insert the cc inside another cc, do i still get the range? I need to insert some text in cc(A) and then put cc(B) inside it, like: (A Some Text (B Some Text) ) Please advice, Thanks.
vimalDev
@Amit did you find any similar scenario working example