I have an Excel 2016 addin (task pane) that inserts about 92000 rows and 100 columns into worksheet. All data is divided on packets on the backend and is sent to the task pane page by packets. On the task pane page java script inserts data from every packet to the current worksheet using Excel.run with parameter { delayForCellEdit: true }.
All data to be inserted is a double array of strings
[
["a_1_1", "a_1_2", "a_1_3", ..., "a_1_100"],
["a_2_1", "a_2_2", "a_2_3", ..., "a_2_100"],
...
["a_92000_1", "a_92000_2", "a_92000_3", ..., "a_92000_100"],
]
Packet - JavaScript object, for example first packet will be
Packet={
"number": "1of920",
"data":[
["a_1_1", "a_1_2", "a_1_3", ..., "a_1_100"],
["a_2_1", "a_2_2", "a_2_3", ..., "a_2_100"],
...
["a_100_1", "a_100_2", "a_100_3", ..., "a_100_100"],
]
}
Function that inserts packet's data is looking like that.
function addDataIntoSheet(Packet){
var startindex = 100 * (parseInt(Packet.number.split('of')[0]) - 1 );
var pExRun = Excel.run({ delayForCellEdit: true }, function (context) {
var currwsheet = context.workbook.worksheets.getActiveWorksheet();
Packet.data.forEach(function (row, index, obj) {
var rowsrange = currwsheet.getRangeByIndexes(startindex + index, 1, 1, row.length);
var rangevalues = new Array(1);
rangevalues[0] = row;
rowsrange.values = rangevalues;
});
return context.sync();
});
pExRun.then(function(){
console.log("Packet " + Packet.number + " inserted");
});
pExRun.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("addRowsAndDataIntoSheet Debug info: " + JSON.stringify(error.debugInfo));
}
});
}
ISSUE: During tests I noticed, that if user started to edit cell of pressed any Excel buttons or resized any row or column the following exception will be thrown: "code":"GeneralException","message":"Wait until the previous call is completed" and as a result some packets are not inserted to the worksheet.
If a user is calmly waiting, data insertion completes without any errors.
QUESTION: Please, recommend how to overcome this issue and to insert large volume of data, despite on the user's activity.