[SOLVED] Export as Excel/CSV

In my download button events I have something like:

    var link = window.document.createElement("a");

    link.setAttribute("href", "data:text/csv;charset=utf-8,%EF%BB%BF" + encodeURI(csv));
    link.setAttribute("download", "export_invoices_" + fileName + ".csv");
    link.click();

the variable csv is comma separate string.

2 Likes

I figured out how to achieve this with Papa Parse. Worked so great that I decided to write a tutorial about it. Comes with a repo and an online demo if you want see how it will look. Hope it can help anyone.

4 Likes

Parfait.
Nice work.
Nicely explanation

I found the easiest fix via BOM; just add the magic at beginning of the string, when creating the buffer for the file export:

let buffer = Buffer('\ufeff'+csvString)

Thanks, KENKEN ā€¦ Great.
I can see correct CSV content with format font on Excell

1 Like

Did you find a solution? Iā€™m also having trouble with the excel format.