2016-11-29 3 views
0

私のOFFICE365タスクペインアプリケーションでコンテンツコントローラー内にテーブルを追加しようとしています。これは私が使用しているコードです。ここでコンテンツコントローラー内でJavaScriptを使用してテーブルを追加する

function createContentControlForTable(tableName, number_columns, number_header, number_body, number_footer) { 
 
     Word.run(function (context) { 
 
      var number_cells = number_header + number_body + number_footer; 
 
      var range = context.document.getSelection(); 
 
    
 
      var myContentControl = range.insertContentControl(); 
 
      myContentControl.tag = "Table name:" + tableName; 
 
      myContentControl.title = "Table name:" + tableName; 
 
      myContentControl.appearance = "Tags"; 
 
      myContentControl.style = "Normal"; 
 
      myContentControl.insertText("", 'replace'); 
 
      myContentControl.cannotEdit = false; 
 
      myContentControl.insertTable(2, 2, Word.InsertLocation.end); 
 
     
 
      context.load(myContentControl, 'id'); 
 

 
      return context.sync().then(function() {    
 
       myContentControl.tag = myContentControl.tag + " id:" + myContentControl.id; 
 
       myContentControl.title = myContentControl.title + " id:" + myContentControl.id; 
 
       showNotification("Table", "Table added successfuly"); 
 
       console.log('Created content control with id: ' + myContentControl.id); 
 

 
       return context.sync().then(function() { 
 
        console.log('Inserted a table in the content control.'); 
 
       }); 
 
      
 
      
 
      }).catch(function (error) { 
 
       console.log('Error: ' + JSON.stringify(error)); 
 
       if (error instanceof OfficeExtension.Error) { 
 
        console.log('Debug info: ' + JSON.stringify(error.debugInfo)); 
 
       } 
 
      }); 
 
      
 
     });

私は私の仕事のために'contentControlObject.insertTable(rowCount, columnCount, insertLocation, values);'を使用しています。

メソッドがhttps://appsforoffice.microsoft.com/lib/1/hosted/office.jsで動作しないため、私は自分のアプリケーションにbeta.version(https://appsforoffice.microsoft.com/lib/beta/hosted/office.js)を使用しました。

しかし、問題はライン'return context.sync().then(function(){'を実行すると、それは誰もがこれで私を助けることができる場合、私はappereciate

ItemNotFound: ItemNotFound\n at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:188232)\n at pi (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:210600)\n at ht (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:210687)\n at g (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:210507)\n at l (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:209093) 

、というエラーを与え、です。ありがとうございました。

答えて

0

JavaScript APIのベータ版を使用していましたが、この問題はAPIに問題が発生したため解決されました。今すぐ

insertTable(rowCount: number, columnCount: number, insertLocation: string, values: string[][]) 

が期待通りに正しく動作しています。

insertLocationの値は、 '開始'、 '終了'、 '前'または '後'、値は任意です(オプション2D配列)

関連する問題