-
Notifications
You must be signed in to change notification settings - Fork 664
How to upload and parse CSV file from server and from desktop
Mathias Rangel Wulff edited this page Sep 25, 2017
·
6 revisions
You can use [AlaSQL][1] library to load and parse CSV data from server or from desktop.
####From Server You can and parse data with CSV() function:
alasql(['SELECT * FROM CSV("mydata")']).then(function(data) {
// Use data
});
####From Desktop If you want to upload data from desktop you can use the following code:
<script src="alasql.min.js"></script>
<p>Select CSV file to read:</p>
<input id="readfile" type="file" onchange="loadFile(event)"/>
<script>
function loadFile(event) {
alasql(['SELECT * FROM FILE(?,{headers:true})',[event]]).then(function(data){
// Process data here
});
}
</script>
See this jsfiddle for a live example
For people working with react.js: you need to use the nativeEvent
from the event:
window.alasql('SELECT * FROM FILE(?,{headers:true})', [e.nativeEvent], function (data) {
console.log(data)
});
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo