0

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 1

0

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!!!

Sign up to request clarification or add additional context in comments.

2 Comments

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.
@Amit did you find any similar scenario working example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.