我想在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);'
我的任務。
由於'insertTable'
方法不能與https://appsforoffice.microsoft.com/lib/1/hosted/office.js一起使用,我使用Office.js的beta_version(https://appsforoffice.microsoft.com/lib/beta/hosted/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)
我appereciate如果有人能幫助我與此有關。謝謝。