2017-12-15 36 views

답변

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뿐만 아니라 유용하게 사용할 수 있습니다 예를 들면 다음과 같습니다.

0

그래서 kendo API를 사용하면 데이터와 매개 변수가있는 WorkbookOptions 객체를 save 메소드로 전달하기 만하면 처음부터 파일을 어셈블 할 수 있습니다.

짧은 예를 들어, JS 코드 :

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>