[英]Add a table inside a Content Controller using javaScript
我正在嘗試在OFFICE365任務窗格應用程序的內容控制器內添加表。 這是我正在使用的代碼。
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);'
為我的任務。
由於'insertTable'
方法不適用於https://appsforoffice.microsoft.com/lib/1/hosted/office.js ,因此我使用了beta_version( https://appsforoffice.microsoft.com/lib/beta/hosted /office.js )的Office.js用於我的應用。
但是問題是,當執行'return context.sync().then(function (){'
行時,會出現錯誤消息,
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)
如果有人可以幫助我,我表示感謝。 謝謝。
我使用JavaScript API的測試版作為單詞,由於API出現問題,因此發生了此問題,現已解決。 現在
insertTable(rowCount: number, columnCount: number, insertLocation: string, values: string[][])
如預期般運作正常。
insertLocation的值可以是“開始”,“結束”,“之前”或“之后”,並且值是可選的(可選2D數組)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.