Skip to content Skip to sidebar Skip to footer

Converting Variable In Javascript To A Csv File

Basically I have a string variable that is composed of two other variables separated by a comma: item = 'Pencil'; amount = 5; entry = item + ',' + amount; *export entry to csv So

Solution 1:

It is perfectly possible, using some FileSaver implementation. I believe it exists natively on IE10, but still needs a shim on other browsers.

I've written a light-weight client-side CSV generator library that might come in handy. Check it out on http://atornblad.se/github/(scroll down to the headline saying Client-side CSV file generator)

As I said, it requires a functioning FileSaver implementation handling calls to window.saveAs(). Check out Eli Grey's solution on http://eligrey.com/blog/post/saving-generated-files-on-the-client-side

When in place, you simply generate and save CSV files on the fly like this:

var propertyOrder = ["name", "age", "height"];

var csv = new Csv(propertyOrder);

csv.add({ name : "Anders",
          age : 38,
          height : "178cm" });

csv.add({ name : "John Doe",
          age : 50,
          height : "184cm" });

csv.saveAs("people.csv");

Post a Comment for "Converting Variable In Javascript To A Csv File"