Forked from mingrammer/download-csv-from-browser.js
Created
January 18, 2022 06:43
-
-
Save huygwen/db9f9d2ed9bcd3daf3bb7817b26384f9 to your computer and use it in GitHub Desktop.
Revisions
-
mingrammer revised this gist
Jan 23, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function createCSV(data) { function downloadCSV(csv) { var csvContent = csv.head + csv.body; if (!csvContent.match(/^data:text\/csv/i)) { csvContent = 'data:text/csv;charset=utf-8,' + csvContent; // use 'data:text/csv;charset=utf-8,\ufeff', if you consider using the excel } var data = encodeURI(csvContent); -
mingrammer renamed this gist
Jan 23, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mingrammer revised this gist
Jan 23, 2018 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,4 +26,7 @@ function downloadCSV(csv) { document.body.appendChild(link); link.click(); document.body.removeChild(link); } var csv = createCSV(data); downloadCSV(csv) -
mingrammer created this gist
Jan 23, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ function createCSV(data) { var lineDelimiter = '\n'; var csv = { 'title': '', 'head': '', 'body': '' }; csv.title = 'csv-title.csv'; csv.head = '...'; // make your own csv head csv.body = '...'; // make your own csv body with `lineDelimiter` (optional) return csv; } function downloadCSV(csv) { var csvContent = csv.head + csv.body; if (!csvContent.match(/^data:text\/csv/i)) { csvContent = 'data:text/csv;charset=utf-8,' + csvContent; } var data = encodeURI(csvContent); var link = document.createElement('a'); link.href = data; link.download = csv.title; document.body.appendChild(link); link.click(); document.body.removeChild(link); }