无法在excel web加载项中创建表



我已经编写了一个函数来创建表

在对该问题进行调查后:-问题是,代码在一张工作表上添加名为"tableName"的表时效果良好,但如果我在另一张名为"tableName"的工作表上插入另一个表,则会引发错误,并且不会插入表,而是不插入内容。我需要将名称应用于表,因为我想根据需要检索表,并且我是在它的名称的帮助下进行的。阅读一篇关于表命名的文章,但如果我重命名工作表名称,以及如何访问它呢。


错误:出了问题!!!RichApi.Error:参数无效、丢失或格式不正确。在新c(https://appsforoffice.microsoft.com/lib/1.1/hosted/excel-web-16.00.js:24:293355)在b.f.processRequestExecutorResponseMessage(https://appsforoffice.microsoft.com/lib/1.1/hosted/excel-web-16.00.js:24:354008)在https://appsforoffice.microsoft.com/lib/1.1/hosted/excel-web-16.00.js:24:352113在ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDeligate.invoke(https://localhost/excelProject/polyfills.js:2753:26)在Object.onVoke(https://localhost/excelProject/vendor.js:57267:33)在ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDeligate.invoke(https://localhost/excelProject/polyfills.js:2752:52)在Zone.push../node_modules/Zone.js/dist/Zone.js.Zone.run(https://localhost/excelProject/polyfills.js:2512:43)在https://localhost/excelProject/polyfills.js:3251:34在ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDeligate.invokeTask(https://localhost/excelProject/polyfills.js:2785:31)在Object.onVokeTask(https://localhost/excelProject/vendor.js:57258:33)


代码

createTable(tableName, startColumn, endColumn, headerData, bodyData, onTableChangedCallback, onSelectionChangedCallback){
Excel.run((context)=> {
var sheet = context.workbook.worksheets.getActiveWorksheet();
let colRange = startColumn+":"+endColumn;//like B2:D2
var sfTable = sheet.tables.add(colRange, true /*hasHeaders*/);
sfTable.name = "tableName";
let headerRow = [];
headerRow.push(headerData);//Below code is hardcoded for 4 column for now

var tableHeaderRange = sfTable.getHeaderRowRange();
tableHeaderRange.values = 
[["Date", "Merchant", "Category", "Amount"]];
sfTable.rows.add(null /*add rows to the end of the table*/, 
[
["1/1/2017", "The Phone Company", "Communications", "$120"],
["1/2/2017", "Northwind Electric Cars", "Transportation", "$142"],
["1/5/2017", "Best For You Organics Company", "Groceries", "$27"],
["1/10/2017", "Coho Vineyard", "Restaurant", "$33"],
["1/11/2017", "Bellows College", "Education", "$350"],
["1/15/2017", "Trey Research", "Other", "$135"],
["1/15/2017", "Best For You Organics Company", "Groceries", "$97"]
]);

if (Office.context.requirements.isSetSupported("ExcelApi", "1.2")) {
sheet.getUsedRange().format.autofitColumns();
//sheet.getUsedRange().format.autofitRows();
sheet.getUsedRange().format.rowHeight = 15;
}
sfTable.onChanged.add(onTableChangedCallback);
sfTable.onSelectionChanged.add(onSelectionChangedCallback)
sheet.activate();
return context.sync(); 
})
.catch((err)=>{
this.errorHandlerFunction(err,"create table")
});

}

错误的原因很不寻常。但问题是表的名称相同。当我以不同的方式命名时,错误被删除了。

最新更新