0

I need to export multiple sheets as excel with different row and column definition. I did not find a way to do it with Ag grid as my column definitions were different, hence I got the data by getDataAsExcel, and appended these blobs using the XLSX library and finally downloaded them using file saver library.

However, the problem is that row and column data groupings are getting lost in the process. Any way to preserve them?

Sample code:



this.spreadSheetArray = [ this.gridApi1.getSheetDataForExcel, this.gridApi2.getSheetDataForExcel];



let workBook = XLSX.utils.book_new();



for (i=0, i<spreadSheetArray.length;i++)

{

let {name,data} = this.spreadSheetArray[i];

let arrayBuffer = await data.arrayBuffer;

let workbookBlob = XLSX.read(arrayBuffer, {type:'array'})



workbookBlob.SheetNames.forEach((sheetName)=> {

let sheet= workbookBlob.Sheets[sheet];

XLSX.utils.book_append_sheet(workBook, sheet, name)

}


}

Finally Downloading using :

let out = XLSX.write(workBook, {bookType : 'xlxs', type:'array'})

saveAs (new Blob([out], { type: 'application/octet-stream'}), 'Download.xlsx')

I tried the above code, sheets are getting appended as different sheets in Excel and getting downloaded. However, row and column groupings are getting lost like it happens for exportDataAsExcel. How can we preserve the data groups for tree structure?

0