Last active
November 16, 2019 04:26
-
-
Save syuji-higa/566536c3b8748dbae820769ad98ea253 to your computer and use it in GitHub Desktop.
JavaScript - create CSV
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 characters
const $link = document.createElement('a') | |
const csvName = 'index.csv' | |
let csv = '' | |
for(let i = 0; 10000 > i; i++) { | |
csv += 'a,b,c,d,e\n' | |
} | |
const blob = new Blob([csv], { type: 'text/csv' }) | |
if (window.navigator.msSaveOrOpenBlob) { | |
// for ie | |
window.navigator.msSaveOrOpenBlob(blob, csvName) | |
} else if (window.URL && window.URL.createObjectURL) { | |
$link.href = window.URL.createObjectURL(blob) | |
$link.download = csvName | |
$link.style.display = 'none' | |
document.body.appendChild($link) | |
$link.click() | |
window.URL.revokeObjectURL($link.href) | |
document.body.removeChild($link) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment