此代码在 Excel 中运行良好,但在 Excel Online 中不起作用。但是,在 Excel Online 中,它会在浏览器日志中生成错误,而且还会在表中插入空行。
我已经学习了这个函数的 API 版本。自 2017 年以来,这似乎在 Excel Online 中有效。
function onWorksheetAdded(eventArgs) {
Excel.run(function (context) {
var table = context.workbook.tables.getItem(INDEX_TABLE_NAME);
var tableRows = table.rows;
var tableColumns = table.columns;
tableRows.load('items'); tableColumns.load('items');
return context.sync().then(function () {
var row = []; for (var j = 0; j < tableColumns.items.length; j++) row.push(0);
var newRow = [];
newRow.push(row);
tableRows.add(0, newRow); //here the mistake, but I can't fix it
return context.sync();
});
}).catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
我在日志中发现了这个:错误:GeneralException:处理请求时出现内部错误。Home.js:204:21 调试信息:{"code":"GeneralException","message":"处理请求时出现内部错误。","errorLocation":"TableRowCollection.add","statement": "var add=rows.add(...);", ...
请帮我解决这个问题。