-1

I have 100 000 lines and i want to export them to CSV, i did manage to export it for few lines but many thousands of lines return network error to my browser and i cannot download it.

        let csvContent = "data:text/csv;charset=utf-8,";
        csvContent += [
            Object.keys(payload[0]).join(";"),
            ...payload.map(item => Object.values(item).join(";"))
        ]
            .join("\n")
            .replace(/(^\[)|(\]$)/gm, "");

        const data = encodeURI(csvContent);
        const link = document.createElement("a");
        link.setAttribute("href", data);
        link.setAttribute("download", "export.csv");
        link.click();
Dacre Denny
  • 29,664
  • 5
  • 45
  • 65

1 Answers1

1

You can not encodeURI with 100000 rows

Use FileSaver.js

var blob = new Blob([csvContent], {type: "text/plain;charset=utf-8"});
saveAs(blob, "export.csv");

Maybe also split the string with Blob.slice() and save several chunks.