question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newbie to js-xlsx - JSON to xlsx conversion with using angular

See original GitHub issue

Anyone can guide me how to convert json to xlsx with using angular?

Here is sample json format: [ { "agentNo":"324234", "subName":"30, Jul 2013 09:24 AM", "Location":"Singapore", "memberName":42, "certNo": "2342234", "Gender":"Male", "dob":"1 may 1987" }, { "agentNo":"444443", "subName":"30, Jul 2013 09:24 AM", "Location":"Malaysia", "memberName":42, "certNo": "2342234", "Gender":"Male", "dob":"1 may 1987" }, { "agentNo":"2342234", "subName":"30, Jul 2013 09:24 AM", "Location":"India", "memberName":42, "certNo": "2342234", "Gender":"Male", "dob":"1 may 1987" } ]

Here is xlsx sample that need to be generated: screen shot 2017-05-24 at 6 16 18 pm

Thanks in advance

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
SheetJSDevcommented, Jan 9, 2018

The new sheet_add_json function can add to an existing worksheet:

var ws = XLSX.utils.aoa_to_sheet([
  ["Member Listing"],
  ["Company Name:", "<Master Policy Holder Name>"],
  ["Report Date:", "<DD/MM/YYYY>"]
]);
XLSX.utils.sheet_add_json(ws, [ { "agentNo":"324234", "subName":"30, Jul 2013 09:24 AM", "Location":"Singapore", "memberName":42, "certNo": "2342234", "Gender":"Male", "dob":"1 may 1987" }, { "agentNo":"444443", "subName":"30, Jul 2013 09:24 AM", "Location":"Malaysia", "memberName":42, "certNo": "2342234", "Gender":"Male", "dob":"1 may 1987" }, { "agentNo":"2342234", "subName":"30, Jul 2013 09:24 AM", "Location":"India", "memberName":42, "certNo": "2342234", "Gender":"Male", "dob":"1 may 1987" } ],{origin:-1});

To control the order of the fields, pass a header option to sheet_add_json:

XLSX.utils.sheet_add_json(ws, [ ... ], {header: ["agentNo", "subName", "memberName", "certNo", "Gender", "dob"], origin:-1});

And to rewrite the column headers, if the objects don’t have the same name as the titles you want, go back and rewrite a new header array in the fourth row (index 3):

XLSX.utils.sheet_add_aoa(ws, [["Agent no", "Subsidiary name", "Member Name", "Cert No", "Gender", "Date of Birth"]], {origin:3});
2reactions
martinnov92commented, May 29, 2017

Hello @samuelkavin I really don´t know this, sorry

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Export JSON to CSV or Excel - Angular 2
Use the XLSX library to convert JSON into XLS file and Download. Working Demo. Source link. Method. Include ...
Read more >
Create Excel from JSON in Angular 9/8 using Exceljs Tutorial ...
This is an awesome library to convert JSON data in formatted and customized Excel files. How to Download XLSX from JSON using ExcelJS...
Read more >
Xlsx To Json (forked) - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
How can I convert an Excel sheet to JSON data in Angular 2?
Actually you can, to convert Excel to JSON you must use an NPM library called XLSX SheetJS/js-xlsx. Create an upload input > create...
Read more >
How to Convert Excel file into JSON by using Angular - YouTube
Initially, when I started working on this requirement, people suggested using any one of the backend libraries to read and convert the excel ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found