I am able to successfully download excel files from my JSON array. The array has many records and based on user input, it is decided if to download all data in one file or multiple. If the action is Yes, then I want to download the data in chunks of 25 rows into multiple files.
Below is my code for download. If there are 75 records then 4 files are downloading. First 3 are correct with 25 records each, but the 4th file is exact duplicate of the 3rd file. In other words, the last file always exports twice even if there are only 2 records, I am still getting 2 files.
How to avoid this issue?
A controller
aProducts =
this.getView().getModel("orderMaterials").getProperty("/MaterialData");
var oModel = [];
for (var i = 0; i <= aProducts.length - 1; i++) {
var items = {};
items.SubmittedBy = submittedBy;
items.MaterialNo= aProducts[i].MaterialNo;
items.LineNumber = i + 1;
oModel.push(items);
}
if (sAction === "YES") {
var i, j, temparray, chunk = 25;
for (i = 0, j = oModel.length; i < j; i += chunk) {
temparray = oModel.slice(i, i + chunk);
oSettings = {
workbook: {
columns: aCols
},
dataSource: temparray
};
var oSpreadsheet = new sap.ui.export.Spreadsheet(oSettings);
oSpreadsheet.build().then(function () {
sap.m.MessageToast.show("Spreadsheet export has finished");
});
}