export to excel in jquery or jqGrid

后端 未结 4 1480
别跟我提以往
别跟我提以往 2020-12-16 06:15

I have a jqGrid where I get data at once from server (java) in JSON format. I want the data in the jqGrid to be exported into Excel format.

Till now I saw this page

4条回答
  •  被撕碎了的回忆
    2020-12-16 06:35

    You don't have to export a file using the Excel format in order to get the data into Excel. It is generally much easier to export to CSV. CSV files should be associated with Excel by default, so it should have the Excel icon by it and everything. XML would work the same way, I think, but the CSV format is much lighter, and does the same job in this case. Converting JSON to CSV is simple:

    var response = JSON.parse(responseJSON).response;
    var csv = arrayToCSV(response);
    
    function arrayToCSV(arr) {
        var columnNames = [];
        var rows = [];
        for (var i=0, len=arr.length; i

提交回复
热议问题