I am working with an array named listTutors that looks like this:
listTutors = [{
countryId: 'tt',
gender: 'both',
levelId: 'tg',
sessionType: 'inPerson',
dashboardStatus: ['notPublished', 'published', 'external'],
subjectId: 'n',
}];
I need to export this array to either an xlsx or csv file. To do so, I utilized the following code using the excelService class:
public exportAsExcelFile(json: any[], excelFileName: string): void {
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
const workbook: XLSX.WorkBook = {
Sheets: { data: worksheet },
SheetNames: ['data'],
};
const excelBuffer: any = XLSX.write(workbook, {
bookType: 'xlsx',
type: 'array',
});
this.saveAsExcelFile(excelBuffer, excelFileName);
}
private saveAsExcelFile(buffer: any, fileName: string): void {
const data: Blob = new Blob([buffer], { type: EXCEL_TYPE });
fileSaver.saveAs(
data,
fileName + '_export_' + new Date().getMonth() + EXCEL_EXTENSION
);
}
The issue I am facing is that when exported, the dashboardStatus field is missing as it is an array field. However, I want the data to be exported in a way that includes notPublished, published, and external inside the same column of dashboardStatus.
https://i.sstatic.net/ruGFM.png
Is there a way to achieve this using the current method or any other approach?