My code successfully exports a file via Excel without any errors. However, the issue I'm facing is that the exported Excel file contains a lot of unnecessary spaces.
The problem is highlighted in the image provided: data from row 123 should be in column 7 but it appears misplaced.
Below is the code snippet responsible for exporting the data:
export function download() {
var header = [];
var finalData = [];
var group = [
{ "group_name": "123" },
{ "group_name": "123b" },
{ "group_name": "123ef" },
{ "group_name": "Accounts Payable" },
{ "group_name": "ADG JET TEAM" },
{ "group_name": "001 Approval" }
];
var member = [
{"001 Approval": "083817 - Ranjeet Kumar (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86f4e7e8ece3e3f2a8edf3ebe7f4b5c6e5e9e8e5e3e8f2f4effea8e5e9eb">[email protected]</a>)"},
{ "001 Approval": "C01747 - Abid Shaikh (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bddcdfd4d993ced5dcd4d6d58cfdded2d3ded8d3c9cfd4c593ded2d0">[email protected]</a>)"},
{ "001 Approval": "C01747 - Abid Shaikh (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="41202328256f322920282a297001222e2f22242f353328396f222e2c">[email protected]</a>)"},
{ "123b": "C01747 - Abid Shaikh (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9b8bbb0bdf7aab1b8b0b2b1e899bab6b7babcb7adabb0a1f7bab6b4">[email protected]</a>)"},
{"123ef": "C01747 - Abid Shaikh (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d1c1f1419530e151c1416154c3d1e12131e1813090f1405531e1210">[email protected]</a>)"}
];
group.forEach(data => {
// Pushing group names to the header
header.push(data.group_name);
});
// Pushing headers to finalData array
finalData.push(header);
// Looping through headers to match with members and grab data corresponding to each header
header.forEach(headerData => {
var temp = [];
member.forEach(memberData => {
if (headerData === Object.keys(memberData)[0]) {
temp.push(memberData[Object.keys(memberData)[0]]);
} else {
temp.push("");
}
});
//Pushing resulting data into the finalData array
finalData.push(temp);
});
// Calling exportToCsv function to generate CSV file
exportToCsv('export.csv',finalData);
}
You can find the exportToExcel code here.