I have a Json data in which I am generating dynamic keys which is having fiscal year quarter and respective values,I need to download the data into xls format which I am successfully able to do, but the problem is when I download the data the order of the xls header is not same as my json keys.Below is my sample data.
var input = [
{
"FPH Level 1": "iphone",
"Geo Level 2": "Austria",
"Geo Level 7": "DACH",
"RTM": "Retail",
"Account": "Austria-epos",
"FY202004": "20%",
"FY202101": "20%",
"FY202102": "20%",
"FY202103": "20%",
"FY202104": "20%",
"Y/Y pt Change": "5%",
"Commentary Y/Y": "TESTING",
"Q/Q pt Change": "4%",
"Commentary Q/Q": "TESTING"
},
{
"FPH Level 1": "iphone",
"Geo Level 2": "Austria",
"Geo Level 7": "DACH",
"RTM": "Retail",
"Account": "Austria-epos",
"FY202004": "20%",
"FY202101": "20%",
"FY202102": "20%",
"FY202103": "20%",
"FY202104": "20%",
"Y/Y pt Change": "5%",
"Commentary Y/Y": "TESTING",
"Q/Q pt Change": "4%",
"Commentary Q/Q": "TESTING"
},
{
"FPH Level 1": "iphone",
"Geo Level 2": "Austria",
"Geo Level 7": "DACH",
"RTM": "Retail",
"Account": "Austria-epos",
"FY202004": "20%",
"FY202101": "20%",
"FY202102": "20%",
"FY202103": "20%",
"FY202104": "20%",
"Y/Y pt Change": "5%",
"Commentary Y/Y": "TESTING",
"Q/Q pt Change": "4%",
"Commentary Q/Q": "TESTING"
},
{
"FPH Level 1": "iphone",
"Geo Level 2": "Austria",
"Geo Level 7": "DACH",
"RTM": "Retail",
"Account": "Austria-epos",
"FY202004": "20%",
"FY202101": "20%",
"FY202102": "20%",
"FY202103": "20%",
"FY202104": "20%",
"Y/Y pt Change": "5%",
"Commentary Y/Y": "TESTING",
"Q/Q pt Change": "4%",
"Commentary Q/Q": "TESTING"
},
{
"FPH Level 1": "iphone",
"Geo Level 2": "Austria",
"Geo Level 7": "DACH",
"RTM": "Retail",
"Account": "Austria-epos",
"FY202004": "20%",
"FY202101": "20%",
"FY202102": "20%",
"FY202103": "20%",
"FY202104": "20%",
"Y/Y pt Change": "5%",
"Commentary Y/Y": "TESTING",
"Q/Q pt Change": "4%",
"Commentary Q/Q": "TESTING"
},
]
here to snipped code I am working to download the data
const xlsData = input
const ws = XLSX.utils.json_to_sheet(xlsData);
const wb = { Sheets: { 'data': ws }, SheetNames: ['data'] };
const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
const data = new Blob([excelBuffer], { type: fileType });
let fileName = `test`
FileSaver.saveAs(data, fileName + fileExtension);
result after the converted it into xls the header are like this
I am excepting the output the be
