我正在尝试向表中添加大量行。我的项目需要添加大表。
请让我知道是否有更好的选择来最大化性能。我应该使用 Range 对象 API 吗?
代码如下所示。
function createSampleSheet(numberOfTimes) {
startTime = performance.now();
Excel.run(function (context) {
var sheets = context.workbook.worksheets;
var sheet = context.workbook.worksheets.getActiveWorksheet();
var expensesTable = sheet.tables.add("A1:H1", true /*hasHeaders*/);
expensesTable.name = "ExpensesTable";
expensesTable.getHeaderRowRange().values = [["Date", "Merchant", "Category", "Category Type", "Class", "NHID", "Collab ID", "WBID"]];
expensesTable.rows.add(null /*add rows to the end of the table*/, [
["1/1/2017", "The Phone Company", "Communications", "BCD","Distinction", "3", "45", "1000036"]
]);
for (i = 1; i <= numberOfTimes; i++) {
expensesTable.rows.add(null /*add rows to the end of the table*/, [
["1/2/2017", "The Mobile Company", "Corporations", "BSD", "First", "2", "36", "1000026"] ]);}
return context.sync()
.then(function () {
endTime = performance.now();
log.logOutput(" " + numberOfTimes + " rows++ " + (endTime - startTime) + " milliseconds OR " + ((endTime - startTime) / 1000) + " seconds")
})
.then(context.sync);
}).catch(function (error) {
console.log("Error: " + error);
BWUI.errorHandler("Upload tables failed : " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}