【问题标题】:Kendo UI multiple grid Excel export [closed]Kendo UI多网格Excel导出[关闭]
【发布时间】:2015-02-22 23:50:17
【问题描述】:

这是我用来将 Kendo 多个网格导出到 Excel 的代码,如何导出所有页面

Example - multiple grid Excel export

【问题讨论】:

    标签: javascript jquery kendo-ui telerik kendo-grid


    【解决方案1】:

    请尝试以下代码 sn-p。

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Kendo UI Snippet</title>
    
        <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css">
        <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.rtl.min.css">
        <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css">
        <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.dataviz.min.css">
        <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.dataviz.default.min.css">
        <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.mobile.all.min.css">
    
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://cdn.kendostatic.com/2014.3.1119/js/jszip.min.js"></script>
        <script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.all.min.js"></script>
      <style>
        #products .k-grid-toolbar
        {
             display:none !important;
        }
       </style>    
    </head>
    <body>
    
    <button id="export" class="k-button"><span class="k-icon k-i-excel"></span>Export to Excel</button>
    <div id="products"></div>
    <div id="orders"></div>
    <script>
      // used to sync the exports
      var promises = [
        $.Deferred(),
        $.Deferred()
      ];
    
      $("#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"
          })
        });
      });
    
      $("#products").kendoGrid({
        toolbar: ["excel"],
                excel: {
                    allPages: true
        },
        dataSource: {
          transport: {
            read: {
              url: "http://demos.telerik.com/kendo-ui/service/Products",
              dataType: "jsonp"
            }
          },
          pageSize: 20
        },
        height: 550,
        pageable: true,
        excelExport: function(e) {
          e.preventDefault();
    
          promises[0].resolve(e.workbook);
        }
      });
    
      $("#orders").kendoGrid({
        dataSource: {
          type: "odata",
          transport: {
            read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
          },
          pageSize: 20,
          serverPaging: true
        },
        height: 550,
        pageable: true,
        columns: [
          { field:"OrderID" },
          { field: "ShipName", title: "Ship Name" },
          { field: "ShipCity", title: "Ship City" }
        ],
        excelExport: function(e) {
          e.preventDefault();
    
          promises[1].resolve(e.workbook);
        }
      });
    </script>
    </body>
    </html>
    

    如果有任何问题,请告诉我。

    【讨论】:

    • 它有效,谢谢。但是如果我编辑我的网格然后更新,它只会导出旧数据而不是新数据。
    • 能否提供您的代码 sn-p?
    • 这是我的代码,感谢您的帮助。 link
    猜你喜欢
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    相关资源
    最近更新 更多