1

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");
                    });
            }
THI
  • 355
  • 11
  • 40
  • What does `oModel` represent? It looks like an array but the name of it suggests that it's an instance of a Model. – Boghyon Hoffmann Jan 15 '19 at 09:46
  • @BoghyonHoffmann I have modified the code. aProducts is a copy of materials data from a data model. Then Model is just an array I am creating to have items in it with key value pairs. I had to do this as "SubmittedBy" is a header level data and not available in MaterialData property. But in excel I want to show show header level data next to all line items too. – THI Jan 15 '19 at 10:17
  • @boghyon Hoffmann, one more observation - I expected the file to print for every cycle of for loop and then oce condition is reached it can break. But it does not happen that way. The control reaches till build of spreadsheet but it does not print till entire for loop is over. I believe for loop is correct, it’s just the printing Is hold off till the loop breaks and on the last time, the loop does not execute extra. At least during debug I don’t see so. Please advise, i tried a lot. – THI Jan 20 '19 at 00:06

0 Answers0