Using jsCSV in your own project is easy, just download the most recent version (see links above), and include JavaScript file in your page. Keep
in mind that jsCSV depends upon the
Prototype library, so you need to first include the Prototype library:
<head>
<script src="prototype.js" type="text/javascript"></script>
<script src="csv.js" type="text/javascript"></script>
</head>
Once you've loaded the library you can begin working with CSV documents and their contents:
<script type="text/javascript">
csvp = new CsvReader({hasHeaders: true, mode: 'quoted'});
csvp.from_url('http://www.example.com/files/test_quoted.csv',
{
onSuccess: displayCSV
}
);
function displayCSV(acsv) {
var text = "";
// create a new document with only those rows where the column 'fname' contains 'aaa'
csv = acsv.where(
{
'fname': 'aaa'
}
);
// createa new document with only the 'fname' and 'lname' columns, and then iterate over
// the rows of that document with the 'each' method.
csv.cols('fname', 'lname').each(
function (row) {
text += 'f: ' + row.get('fname') + ', l: ' + row.get('lname') + "\n";
}
);
$('csvArea').update(text);
}
</script>