Export to excel, both single grid to single file and multiple grid to single file

4 posts, 0 answers
  1. Matias
    Matias  avatar
    24 posts
    Member since:
    Mar 2016

    Posted 18 Oct Link to this post

    Is there any way to achieve this? I found that I have to choose between one of the two options, and I'd like to keep them both.

    Thanks in advance.

  2. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 20 Oct Link to this post

    Hello Matias,

    The following example demonstrates how to export multiple grid to a single Excel document. Generally you can modify the code to export only a single grid or multiple grids. Nevertheless, in case you need to export two files, one that will contains the single grid and another one that will contains the multiple grids you can execute the same logic to export twice. Please check out the following code snippet.
    $("#export").click(function (e) {
        // trigger export of the products grid
        $("#products").data("kendoGrid").saveAsExcel();
        // trigger export of the orders grid
        $("#orders").data("kendoGrid").saveAsExcel();
        
        // wait for both exports to finish
        $.when.apply(null, promises)
         .then(function (productsWorkbook, ordersWorkbook) {
     
             // create a new workbook using the sheets of the products and orders workbooks
             var sheets = [
               productsWorkbook.sheets[0],
               ordersWorkbook.sheets[0]
             ];
     
             sheets[0].title = "Products";
             sheets[1].title = "Orders";
     
             var workbook = new kendo.ooxml.Workbook({
                 sheets: sheets
             });
     
             // save the new workbook,b
             kendo.saveAs({
                 dataURI: workbook.toDataURL(),
                 fileName: "ProductsAndOrders.xlsx"
             })
         });
     
        // this will create another Excel document.
            $("#products").data("kendoGrid").saveAsExcel();
            $.when.apply(null, promises)
            .then(function (productsWorkbook) {
     
            // create a new workbook using the sheets of the products and orders workbooks
            var sheets = [
              productsWorkbook.sheets[0]
            ];
     
            sheets[0].title = "Products";
     
            var workbook = new kendo.ooxml.Workbook({
                sheets: sheets
            });
     
            // save the new workbook,b
            kendo.saveAs({
                dataURI: workbook.toDataURL(),
                fileName: "ProductsAndOrders.xlsx"
            })
        });
    });


    Regards,
    Kostadin
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Matias
    Matias  avatar
    24 posts
    Member since:
    Mar 2016

    Posted 20 Oct in reply to Kostadin Link to this post

    Hello Kostadin,

    As I understand the code snippet you provided, with the same trigger (e.g. a button) I can fire two exports at the same time, one with every grid in a single file, and one with the desired grid in another file, generating the 2 files at the same time.

    What I would like to achieve is, triggering the 2 exports separately, for example with 2 different buttons. In "ButtonA" I fire the script that export every grid in a single file, and in "ButtonB" I fire the export that generates a file for a single grid.

    Is that possible?

    Thank you very much.

  5. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 24 Oct Link to this post

    Hi Matias,

    You can achieve that by using a single button to export the multiple grid and a single button to export only one grid. The multiple grid exporting is demonstrated in the provided sample and you can use the following code to export only a single grid.
    $("#exportSingle").click(function () {
        singleExport = true;
        $("#products").data("kendoGrid").saveAsExcel();
    });

    Keep in mind you need to check is a single export button is clicked when products_excelExport function is called. For your convenience, I modified the sample and attached it to this thread.

    I hope this information helps. 

    Regards,
    Kostadin
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready