Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / Export multiple grids to one excel file

Export multiple grids to one excel file

New Discussion
Amos Silberman
Amos Silberman asked on Aug 24, 2017 7:29 AM

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

Sign In to post a reply

Replies

  • 0
    Nadia Robakova
    Nadia Robakova answered on Nov 30, 2015 12:32 PM

    Hi,

    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://www.igniteui.com/infragistics-excel/overview

     

    • 0
      Amos Silberman
      Amos Silberman answered on Nov 30, 2015 12:36 PM

      Thanks for the quick response.

      I was asking about exporting the igGrid – the javascript control, not the ASP.NET server control.

      thanks

      • 0
        Hristo Anastasov
        Hristo Anastasov answered on Dec 2, 2015 9:09 AM

        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.

      • 0
        Rob Smith
        Rob Smith answered on Dec 3, 2015 9:27 PM

        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

      • 0
        Hristo Anastasov
        Hristo Anastasov answered on Dec 9, 2015 1:52 PM

        Hi,

        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.

      • 0
        Alexis Michaelides
        Alexis Michaelides answered on Aug 3, 2017 12:29 PM

        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

      • 0
        Alexis Michaelides
        Alexis Michaelides answered on Aug 3, 2017 7:34 PM

        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

      • 0
        Thufail
        Thufail answered on Aug 13, 2017 1:36 AM

        Hi,

        Is there any way to export two igGrids into single sheet within a workbook.

        Thanks

      • 0
        Hristo Anastasov
        Hristo Anastasov answered on Aug 14, 2017 7:48 AM
      • 0
        Thufail
        Thufail answered on Aug 14, 2017 4:18 PM

        Hi,

        The URL talks about exporting 2 iGGrids into  two separate sheets. Is there a way to combine two igGrids into one single sheet.

        Thanks

      • 0
        Hristo Anastasov
        Hristo Anastasov answered on Aug 24, 2017 7:29 AM

        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."

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Amos Silberman
Favorites
0
Replies
11
Created On
Aug 24, 2017
Last Post
8 years, 6 months ago

Suggested Discussions

Created by

Created on

Aug 24, 2017 7:29 AM

Last activity on

Feb 19, 2026 3:18 PM