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:

Thanks in advance
@samuelkavin see my answer to your comment on #610
@jomel, thank you for response. All done. Now, I stuck with settting up the title of the excel file which is Member Listing, Company Name and Report Date on A1, A2 and A3 cell. Any idea?
@martinnov92, is it possible insert custom 3 row before header? something like this:

Hello @samuelkavin I really don麓t know this, sorry
I added an example on exporting a xlsx file from an array of jsons on Angular2/4:
https://github.com/bogdancar/xlsx-json-to-xlsx-demo-Angular2
@bogdancar your demo isnt avaialble
@indunilw Sorry, fixed the link.
@samuelkavin @jomel did you solve the custom header portion of the sheet, where you want common data for the table in a top section, is this possible? the memberListing portion in the OPs example
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});
@SheetJSDev OMG! Amazing! This makes it SO much easier. Thank you!
Most helpful comment
The new
sheet_add_jsonfunction can add to an existing worksheet:To control the order of the fields, pass a header option to sheet_add_json:
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):