Tuesday, October 13, 2015

Excel export from JSON

                               

I have a previous posts on generating Excel file from a table. Unfortunately they do not work in IE. We can generate Excel file from a JSON file as shown below

What do we need?

  • JSONtoCSVConverter javascript file.
  • JSON Data
  • Jquery 
This line is important
 JSONToCSVConvertor(data, "Blog Report", true);


 1st parameter accepts data
 2nd parameter we specify the file name
 3rd paramter we spcecify whether we need label



<html>
<head>
    <title>Internet explorer download</title>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
     <script src="../scripts/Excel/ExcelExport.js"></script>
</head>
<body>
    <div align="center">
        <h3><u>Enter JSON data</u></h3>
        <div class="mydiv">
                   <textarea cols="100" rows="15" class="txtarea" id="txt">[{"Blog Name":"PrathapKudupusBlog","Date":"30 Jul 2013 09:24 AM","Type":"Technical","Author"
:"Prathap Kudupu"},
{"Blog Name":"ABCBlog","Date":"30 Jul 2011 09:24 AM","Type":"Technical","Author"
:"ABC"},
{"Blog Name":"XYZBlog","Date":"30 Jul 2011 09:24 AM","Type":"Technical","Author"
:"XYZ"}]<
span style="line-height: 18.5625px;"></textarea>
  </div> <br> <h3><u>Click below button to download <strong>CSV</strong> file for internet explorer and other browsers</u></h3> <br> <button class="download">Download CSV</button></div> </body> </html>



$(document).ready(function () {
    $('.download').click(function () {
        var data = $('#txt').val();
        if (data == '')
            return;
        JSONToCSVConvertor(data, true);
    });

});

2 comments:

  1. doesn't work in IE. There is a limit on number of characters for URL value in IE

    ReplyDelete
  2. Thanks for in the info. I wrote this article 2 years back and did not validate the size limit

    ReplyDelete