Performance of Excel JavaScript API (ExcelApi1.1) when creating a table/range with a large data set (+50k rows) is slow (5 seconds per 50k rows)

蓝咒 提交于 2020-01-03 05:43:11

问题


Performance is below expectations when using the Excel JavaScript API (ExcelApi1.1) to create a table and add data via a web Excel add-in, compared to rendering a table using the ‘Get Data’ function (on the Data tab)

Initially the implementation of the web Excel Add-in was identical to that provided in the tutorial ‘Create an Excel task pane add-in’. But the performance of adding rows (all rows or one at a time) directly to the table was significantly worse. https://docs.microsoft.com/en-us/office/dev/add-ins/tutorials/excel-tutorial

Following Microsoft advice on ‘Performance optimization using the Excel JavaScript API’ the implementation was changed to create a range then add this range to a new table, before call context.sync(). https://github.com/OfficeDev/office-js-docs-pr/blob/master/docs/excel/performance.md

But this performance is still poor, our expectations is for Excel to render the table in less than 10 seconds for 400k rows, similar to using the ‘Get Data’ function.

The core of the web Excel Add-in is as follows:

Excel.run(function(context) {

// Temporally suspend the auto calcatuion when you try to do large dataset read/wirte operation
if (Office.context.requirements.isSetSupported('ExcelApi', 1.6)) {
    // Only supported in 1.6 onwards
    context.application.suspendApiCalculationUntilNextSync();
}

const currentWorksheet = context.workbook.worksheets.getActiveWorksheet();

var rowCount = dataValueArray.length;
console.log('data.length=' + rowCount);

var range = currentWorksheet.getRange("A2:I" + (rowCount + 1));
range.values = dataValueArray;

const expensesTable = currentWorksheet.tables.add("A1:I" + (rowCount + 1), true /*hasHeaders*/);
expensesTable.name = "ExpensesTable";

expensesTable.getHeaderRowRange().values = [["Timestamp", "NanoSeconds", "OPCServer", "Source", "Severity", "Message", "Condition", "Category", "SequenceNo"]];

var ret = context.sync().then(function() {
    console.log('staticDataAlarms: context.sync() complete:(s)', + (performance.now() - start) / 1000);
});

return ret;
})

A web Excel add-in is used to create a range containing a large number of rows (using static test data), add this range to a new table, then call context.sync() to cause Excel to render the table. Times taken for Excel to complete the render of tables with different numbers of rows is given below:

50k - 6s, 100k - 11.5s, 200k - 24.3s, 300k - 34.7s, 400k - 45.4s, 500k - 62.4s,

These times are below expectations, compared to rendering a table using the ‘Get Data’ function (on the Data tab) and retrieving the same number of rows direct from a SQL Server database. Times taken for Excel to complete the render of tables with different numbers of rows is given below, times include the SQL Query execution:

50k - 2.6s, 100k - 2.8s, 200k - 6.0s, 300k - 7.0s, 400k - 9.7s, 500k - 11.2s,

Tests were performed on the following environments:

Excel - Office 2019 32 bit, Version 1903 (Build 11425.20244)

Excel – Office 2016 32 bit, Version 16.0.4738.1000

Excel – Office online, Build 16.0.11615.35054

Also see related Issue: Excel JavaScript API (ExcelApi1.1) fails when creating a table/range with a large data set (400k-600k rows) returning the error “GeneralException”

来源:https://stackoverflow.com/questions/55923941/performance-of-excel-javascript-api-excelapi1-1-when-creating-a-table-range-wi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!