0

I want to export huge amount of html table data around 5 lakhs from table to excel the code is working for small amount of data but when records get much more it gives error Maximum call stack size exceeded. The code :

$scope.export= function () {
        if ($scope.u.Data.did== 1) {
            $scope.temp = $scope.list;
            if ($scope.temp.length > 0) {
                var table = GenerateHTMLTable($scope.temp);
                $(table).table2excel({
                    filename: $window.location.hash.substring(3)
                });
            }
        }
        else if ($scope.u.Data.did!= 1) {
            $scope.temp = $scope.list;
            if ($scope.temp.length > 0) {
                var table = GenerateHTMLTable($scope.temp);
                $(table).table2excel({
                    filename: $window.location.hash.substring(3)
                });
            }
        }
    }

function GenerateHTMLTable(json) {
        var table = document.createElement("TABLE");
        var col = [];
        for (var key in json[0]) {
            if (key !== "$$hashKey") {
                col.push(key);
            }
        }
        var row = table.insertRow(-1);
        for (var i = 0; i < col.length; i++) {
            var headerCell = document.createElement("TH");
            headerCell.innerHTML = col[i];
            row.appendChild(headerCell);
        }
        for (var i = 0; i < json.length; i++) {
            row = table.insertRow(-1);
            for (var j = 0; j < col.length; j++) {
                var cell = row.insertCell(-1);
                cell.innerHTML = json[i][col[j]];
            }
           }
           return table;
         }

suggest if any change required in the code.Thanks

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
faraz
  • 57
  • 1
  • 4
  • 12
  • Why is this tagged as C#? – ckuri Feb 03 '23 at 08:25
  • Check this answer https://stackoverflow.com/questions/4895230/why-phpexcel-does-not-allow-to-write-more-than-5000-rows – Grumpy Feb 03 '23 at 10:40
  • 1
    Consider using some libraries if you absolutely have to achieve this in the front end. I'd suggest you to achieve this in the server side. – srvts Feb 09 '23 at 15:43

0 Answers0