Using word javaScript API - Add a table inside a Content Controller RRS feed

  • Question

  • I am creating a task pane app for Office 365 and I need to add a table inside a content controller. I have tried to use 'insertTable' method as follows.

    function createContentControlForTable(tableName, number_columns, number_header, number_body, number_footer) {
   (context) {
                var range = context.document.getSelection();
                var myContentControl = range.insertContentControl();
                myContentControl.tag = "Table name:" + tableName;
                myContentControl.title = "Table name:" + tableName;
                myContentControl.appearance = "Tags";
       = "Normal";
                myContentControl.insertTable(number_header, number_columns,'End');
                myContentControl.insertText("", 'replace');
                myContentControl.cannotEdit = false;
                context.load(myContentControl, 'id');
                return context.sync().then(function () {
                    myContentControl.tag = myContentControl.tag + " id:" +;
                    myContentControl.title = myContentControl.title + " id:" +;
                    showNotification("Table", "Table added successfuly");
                    console.log('Created content control with id: ' +;
                    return context.sync().then(function () {
                        //showNotification("Success", "Section added succesfully.")
           .catch(function (error) {
               console.log('Error: ' + JSON.stringify(error));
               if (error instanceof OfficeExtension.Error) {
                   console.log('Debug info: ' + JSON.stringify(error.debugInfo));

    I have used the Office.js reference as follows in the html. 

    <script src="" type="text/javascript"></script>

    When I run the code, I am getting a run time error as follows.

    JavaScript runtime error: Object doesn't support property or method 'insertTable' 'iexplore.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'.

    Could you please tell me what is causing this error. 

    Thank you.


    Tuesday, November 22, 2016 10:48 AM

All replies

  • Hi,

    this error says that the method 'insertTable', which you are using, is not a member of the Office.js file. Did you accidentally make a typo or called the wrong method?

    Regards, Sjoukje. Blog | LinkedIn | Twitter

    Tuesday, November 22, 2016 11:31 AM
  • Hi,

    I don't think I have made a typo. But I am not sure that I have called the method wrong.

    contentControlObject.insertTable(rowCount, columnCount, insertLocation, values);

    As per the link

    , insertTable method is available in the Office.js 1.3 version. If you know, please help me with this. 

    Tuesday, November 22, 2016 11:54 AM