I'm looking for import data from a csv file to a handsontable. I only found answers to export in csv but I don't want to. Any idea please !
Asked
Active
Viewed 2,663 times
0
-
Just write a function or something that pulls the data from the CSV and pushes it to the table. – Ellis Jul 01 '15 at 12:58
-
agreed with Ellis, look here: http://stackoverflow.com/questions/23762822/javascript-loading-csv-file-into-an-array – ZekeDroid Jul 01 '15 at 14:48
1 Answers
0
I've developed some javaScript code that will upload xml to handsontable. You may be able to adapt this:
Use an XMLHttpRequest to upload a file (this would be from local machine) something like this:
function uploadFile()
{
var url = $("#fileUpload").val(); //gets filename from html input field
var xhr = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
xhr.onreadystatechange = XHRhandler;
xhr.open("GET", url, true);
xhr.send(null);
function XHRhandler() {
if (xhr.readyState == 4) {
//the raw text from the file
var rawText = xhr.responseText;
xhr = null;
makeDataArray(); //Make a function that uses the rawText
//and parse out an array for the data portion of the table.
makeTable(); //Make a function that renders the table with the data
}
}
}
Be sure that all of the things you do to get the data from the xhr call is in that loop otherwise you'll have an empty variable (due to the asynchronous nature of the call).
Use some of this html code to add in the file box:
<input type="text" id="fileUpload" value="file.csvX"/> </input>
<input id="upload" type="button" value="Upload" onclick="uploadFile();"/> </input>

mudrock
- 75
- 1
- 9
-
Thank you, I'm on an other side of my project, and this doesn't work anymore. So, I will look at this again with your advice :) – Erlaunis Jul 10 '15 at 14:50