0

I get the JSON by AJAX. Now, I need to export the JSON to Excel. What should I do?

Here is some code:

$.ajax({
    url: '../getData.ashx',
    type: 'post',
    dataType: 'json',
    data: {},
    success: function (data) {
        var json = data.result;

    },
    error: function () {
    }
})
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
iCnG
  • 3
  • 1
  • 4
  • Please post relevant code of what you've tried. Posting code not relevant to the problem doesn't help and won't prevent the question from being downvoted or closed. As it is, you are asking "How can I create an Excel file in Javascript?". The question can be closed for several reasons - as too broad, as asking for a library (just google for "javascript excel"), as duplicate [of this one](http://stackoverflow.com/questions/333537/how-to-generate-excel-through-javascript) and others – Panagiotis Kanavos May 28 '15 at 09:08

2 Answers2

0

Why don't you create a CSV from the data, which can be opened by Excel. Since you don't need any frameworks, this would be the most straight-forward solution.

http://en.wikipedia.org/wiki/Comma-separated_values

Jan B.
  • 6,030
  • 5
  • 32
  • 53
0

There is already a topic on the site, concerning the json to excel conversion. Please take a look at this topic, there is an example code:

Export JSON to CSV or Excel with UTF-8 (e.g. Greek) encoding using JavaScript

Community
  • 1
  • 1
  • There are a lot of similar questions, like [JS-XLSX](https://github.com/SheetJS/js-xlsx), [ng-xlsx](https://github.com/srijken/ng-xlsx) and a few libraries as well. It's a matter of searching and picking a script or library – Panagiotis Kanavos May 28 '15 at 09:24
  • I have seen it ,but not what i want and it's low efficiency when handle the big data,so I do it in another file (such as .ashx file),thank you for help! – iCnG May 29 '15 at 09:29
  • Actually, when working with big data, in my opinion, you have to personalize your code (write the script that best fits your needs). If you have many records, i think the best way should be passing the json as text to an external process that treats the data and returns a response when finished. The output may be a file in the CSV format that you can download when the response in received. Let the server do the big work. – Ivo Georgiev May 29 '15 at 13:47