【问题标题】:Possibility to export multiple kendo grids for angular to excel可以将多个剑道网格导出为 angular 到 excel
【发布时间】:2017-12-15 15:19:22
【问题描述】:

有文档功能可以将多个剑道网格导出到一个用于 jQuery 网格的 excel 文件中,但在网站上没有任何东西等于 angular。

但是也许有人设法为 Angular 做到了?

【问题讨论】:

    标签: angular kendo-ui telerik kendo-grid


    【解决方案1】:

    您可以导出多个数据集(一个网格可以绑定到每个数据集,但 Excel 导出不是必需的)。这是一个例子:

    <button type="button" class="k-button" (click)="save(excelexport, excelexport1)">Export To Excel</button>
    
            <kendo-excelexport [data]="data" fileName="Products.xlsx" #excelexport>
                <kendo-excelexport-column field="ProductID" [locked]="true" title="Product ID" [width]="200">
                </kendo-excelexport-column>
                <kendo-excelexport-column field="ProductName" title="Product Name" [width]="350">
                </kendo-excelexport-column>
                <kendo-excelexport-column field="UnitPrice" title="Unit Price" [width]="120">
                </kendo-excelexport-column>
          </kendo-excelexport>
            <kendo-excelexport [data]="data1" fileName="Products.xlsx" #excelexport1>
                <kendo-excelexport-column field="ProductID" [locked]="true" title="Product ID" [width]="200">
                </kendo-excelexport-column>
                <kendo-excelexport-column field="ProductName" title="Product Name" [width]="350">
                </kendo-excelexport-column>
                <kendo-excelexport-column field="UnitPrice" title="Unit Price" [width]="120">
                </kendo-excelexport-column>
          </kendo-excelexport>
    
    public save(component1, component2): void {
          Promise.all([component1.workbookOptions(), component2.workbookOptions()]).then((workbooks) => {
            workbooks[0].sheets = workbooks[0].sheets.concat(workbooks[1].sheets);
            component1.save(workbooks[0]);
          });
        }
    

    http://plnkr.co/edit/nAGrfaM2H4VK6tKIFTyP?p=preview

    Excel Export documentation 也可能派上用场。

    【讨论】:

      【解决方案2】:

      所以解决方案是使用 kendo API,它允许我们从头开始组装文件,只需将带有数据和参数的 WorkbookOptions 对象传递到保存方法。

      简短的例子js-code:

       public save(component): void {
          const options = {
              sheets: [
                  {
                      name: 'Sheet One',
                      filter: {
                          from: 0,
                          to: 1
                      },
                      columns: [
                          {
                              width: 100
                          },
                          {
                              width: 200
                          },
                      ],
                      rows: [
                          {
                              cells: [
                                  {
                                      color: '#ffffff',
                                      background: '#808080',
                                      value: 'First name'
                                  },
                                  {
                                      color: '#ffffff',
                                      background: '#808080',
                                      value: 'Last Name'
                                  }
                              ]
                          },
                          {
                              cells: [
                                  {
                                      value: 'Erick'
                                  },
                                  {
                                      value: 'Carthman'
                                  }
                              ]
                          },
                          {
                              cells: [
                                  {
                                      value: 'Stan'
                                  },
                                  {
                                      value: 'Marzh'
                                  }
                              ]
                          }
                      ]
                  },
                  {
                      name: 'Sheet Two',
                      filter: {
                          from: 0,
                          to: 1
                      },
                      columns: [
                          {
                              width: 100
                          },
                          {
                              width: 200
                          },
                      ],
                      rows: [
                          {
                              cells: [
                                  {
                                      color: '#ffffff',
                                      background: '#808080',
                                      value: 'Name'
                                  },
                                  {
                                      color: '#ffffff',
                                      background: '#808080',
                                      value: 'Length'
                                  }
                              ]
                          },
                          {
                              cells: [
                                  {
                                      value: 'Vasya'
                                  },
                                  {
                                      value: 10
                                  }
                              ]
                          },
                          {
                              cells: [
                                  {
                                      value: 'Petya'
                                  },
                                  {
                                      value: 19.5
                                  }
                              ]
                          }
                      ]
                  }
              ]
          };
          component.save(options);
      

      标记:

              <button type="button" class="k-button" (click)="save(excelexport)">Export To Excel</button>
          <kendo-excelexport fileName="Products.xlsx" #excelexport></kendo-excelexport>
      

      【讨论】:

        猜你喜欢
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        • 2017-10-25
        • 1970-01-01
        • 1970-01-01
        • 2015-06-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多