0

I am using angularjs and exporting data in excel from the table that has been uploaded.

I am using the following code:

function (e) {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent($('div[id$=exportable]').html()));
e.preventDefault();

It is allowing me to download the file but extension is missing. Can you pls guide me how to change file name and extension both for the same?

Thanks

1 Answers1

0

Excel to JSON

This is basically what you are looking for, some way to turn excel to JSON data with JavaScript. Here is a link to an article about how it can be done using XLSXReader in a web app along with AngularJS.

Sample Code

$(function() {
    $("#xlsxFile").change(function(event) {
        var file = this.files[0],
            sheets;
        XLSXReader(file, true, function(xlsxData) {
            sheets = xlsxData.sheets;
            // Do somehting with sheets. It's a
            // Javascript object with sheet names
            // as keys and data as value in form of 2D array
        });
    });
}); 

Working Example

Here is a working example of the code. You can upload a csv file and have it turned into JSON.

I hope this helps.

Joe Lloyd
  • 19,471
  • 7
  • 53
  • 81
  • Thanks for the response. But I want to export the data in the java script table to excel so that I can do some modifications. I am able to acheive that, just I want a filename of my choice along with the extn as per my choice. – Aashish jindal Sep 26 '15 at 21:22
  • oh I see, sorry I misread. so you want to turn JSON into csv? – Joe Lloyd Sep 26 '15 at 21:25