Hi,
Is it possible to export multiple grids to the same excel file?
Each grid will be on a different sheet.
This feature is available in the ASP.NET excel export, as you can use the Export method, and pass it the grid to be exported and an Excel sheet.
Thanks
Thank you for using our forum.
Yes, it is possible to export 2 grids in same excel file.
You can look at our sample:
https://es.infragistics.com/samples/aspnet/data-grid/excel-exporter
Thanks for the quick response.
I was asking about exporting the igGrid - the javascript control, not the ASP.NET server control.
thanks
Hello,
I am interested in the same thing. Please give an example of how to set the column names correctly on the second worksheet.
Also, how would this be done with 3 or 4 or 5 grids?
Thank you
Achieving the same with more grids would follow the same approach - returning false in the exportEnding event and executing the same logic with the workbooks in next grid exporting event. Setting the columns name correctly would involve just writing value to the cell in the exportEnding event, like:
worksheet.rows(0).setCellValue(0, "text") - this will write "text" into the the first cell in the first row of the worksheet, which would be the headers row.
How would I know the header values to be inserted here. In sample we are using the hardcoded text but in real we need it to come via grid's own data.
Please post the complete sample
Managed to fix this myself after a bit of R&D. Posting complete code below (please excuse formatting)
function exportSecondGrid(workbook) { var headerArr = []; $.ig.GridExcelExporter.exportGrid($("#grid1"), { fileName: "igGrid", worksheetName: "Sheet2" }, { headerCellExporting: function(sender, args) {// We will save all the headers coming to our array for retrieval later on headerArr.push(args.headerText); if (args.columnIndex === 0) { sender._workbook = workbook; sender._workbook.worksheets().add( sender._worksheet.name()); sender._worksheet = sender._workbook.worksheets(1); } }, exportEnding: function(sender, args) { // Now use the array of headers to be updated var row = sender._worksheet.rows(0); for(var ind=0; ind < headerArr.length; ind++) { row.setCellValue(ind, headerArr[ind]); } } } );
}
Use this with the original first function and everything will be perfect
Is there any way to export two igGrids into single sheet within a workbook.
Hi Tufail,
Each grid is exported into a table region in a worksheet, but Excel allows only one table region to be created within a single worksheet, so trying to export second grid into the same sheet will result in an error:
"There in another table in the specified region."
The URL talks about exporting 2 iGGrids into two separate sheets. Is there a way to combine two igGrids into one single sheet.
Please refer to https://es.infragistics.com/community/forums/f/ignite-ui-for-javascript/104362/export-multiple-grids-to-one-excel-file/493792#493792 for an overview of how to export to grids into the same worksheet.