Programmatically generate a CSV table along with a download link for it.
Created
January 5, 2014 02:57
-
-
Save joyrexus/8263718 to your computer and use it in GitHub Desktop.
Generate data attachments
This file contains 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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
a { | |
margin: 50px; | |
font-family: "Helvetica Neue"; | |
font-weight: 700; | |
font-size: 75px; | |
color: steelblue; | |
text-decoration: none; | |
letter-spacing: -5px; | |
-webkit-font-smoothing: antialiased; | |
} | |
a:hover { | |
color: orange; | |
} | |
</style> | |
<body> | |
<script> | |
var rows = [ 'A,B,C', '0,1,2', '3,4,5' ]; | |
var csv = rows.join("\n"); // join rows with newlines | |
var a = document.createElement('a'); | |
a.href = 'data:attachment/csv,' + encodeURI(csv); | |
a.download = 'data.csv'; | |
a.innerText = 'click me!'; | |
document.body.appendChild(a); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment