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 have prepared a sample demonstrating how you can export two igGrids into the same excel file into different worksheets. Since this is a custom approach it may need a slight modification if you want to export more than two grids. The approach that is taken follows the scenario that:
1) Export first grid and handle the exportEnding event
2) In the exportEnding event call a function that exports the second grid and pass the workbook that contains the first grid as argument to the function
exportEnding: function(sender, args) { exportSecondGrid(args.workbook); return false; }
3) Handle the headerCellExporting event for the second grid, where you change the default workbook with the workbook we already have. Also we add a new worksheet to this workbook, where the second grid will be exported:
headerCellExporting: function(sender, args) { if (args.columnIndex === 0) { sender._workbook = workbook; sender._workbook.worksheets().add(sender._worksheet.name()); sender._worksheet = sender._workbook.worksheets(1) } },
Please note there is a slight drawback of this scenario: since we add the new worksheet when exporting headers had started, the second worksheet will have default strings applied to column names. This can be corrected for example in headerCellExported event. Please let me now if you would need assistance on how to achieve this.
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.
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.
Is there any way to export two igGrids into single sheet within a workbook.
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