Skip to content

Instantly share code, notes, and snippets.

@namieluss
Created November 18, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namieluss/bec953782b4da5633d31bf2fc6ae1be6 to your computer and use it in GitHub Desktop.
Save namieluss/bec953782b4da5633d31bf2fc6ae1be6 to your computer and use it in GitHub Desktop.
window.onload = function() {
document.getElementById('csv-file').addEventListener(
'change', preview_csv, false
);
}
function preview_csv(e) {
if (!e.target.files.length) {
alert("Please choose a csv file...");
return
}
const file = e.target.files[0];
// parse file then pass to html generator
Papa.parse(file, {
complete: function(result) {
if (result.data && result.data.length > 0) {
htmlTableGenerator(result.data)
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment