1

I need to upload and convert JSON files like

[
    {
        "First Name": "Paul",
        "Last Name": "Craig",
        "Gender": "Male",
        "Age": 18,
        "Phone": "072-8074-38"
    },
    {
        "First Name": "Alan",
        "Last Name": "Richards",
        "Gender": "Male",
        "Age": 22,
        "Phone": "616-2480-27"
    }
]

to excel file. Before downloading the file user must be able to preview the file. This needs to be done using HTML and javascript

1 Answer 1

3

You can show the user the JSON Data using a normal html table

then you can do it like this:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.1/xlsx.full.min.js"></script> 
        <script>
            function ExportData()
            {
               filename='people.xlsx';
               data=[
               {
                  "First Name": "Paul",
                  "Last Name": "Craig",
                  "Gender": "Male",
                  "Age": 18,
                  "Phone": "072-8074-38"
               },
               {
                  "First Name": "Alan",
                  "Last Name": "Richards",
                  "Gender": "Male",
                  "Age": 22,
                  "Phone": "616-2480-27"
              }
              ]
                var ws = XLSX.utils.json_to_sheet(data);
                var wb = XLSX.utils.book_new();
                XLSX.utils.book_append_sheet(wb, ws, "People");
                XLSX.writeFile(wb,filename);
             }
        </script>

This will let you download the json data as an excel file!

Reference: Javascript JSON to Excel file download

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.