엑셀 내보내기

    The Ignite UI for Angular Excel Exporter service can export data in Microsoft® Excel® format from raw data (array) or from the IgxGrid, IgxTreeGrid and IgxHierarchicalGrid components. The exporting functionality is encapsulated in the IgxExcelExporterService class and the data is exported in MS Excel table format. This format allows features like filtering, sorting, etc.

    Angular Excel Exporter Example

    Usage

    To start using the IgniteUI Excel Exporter first import the IgxExcelExporterService in the app.module.ts file and add the service to the providers array:

    // app.module.ts
    
    ...
    import { IgxExcelExporterService } from 'igniteui-angular/grids/core';
    // import { IgxExcelExporterService } from '@infragistics/igniteui-angular'; for licensed package
    
    @NgModule({
      providers: [ IgxExcelExporterService ]
    })
    
    export class AppModule {}
    
    Note

    v12.2.1 이상에서는 내보내기 서비스가 루트에서 제공됩니다. 즉, 더 이상 AppModule 공급자에서 이를 선언할 필요가 없습니다.

    내보내기 프로세스를 시작하려면 구성 요소 템플릿의 버튼 핸들러를 사용할 수 있습니다.

    <button (click)="exportButtonHandler()">Export Data to Excel</button>
    

    You may access the exporter service by defining an argument of type IgxExcelExporterService in the component's constructor and the Angular framework will provide an instance of the service. To export some data in MS Excel format you need to invoke the exporter service's exportData method. This method accepts as a first argument the data you want to export and the second argument is of type IgxExcelExporterOptions and allows you to configure the export process.

    다음은 구성 요소의 TypeScript 파일에서 내보내기 프로세스를 실행하는 코드입니다.

    // component.ts
    
    ...
    import { IgxExcelExporterService, IgxExcelExporterOptions } from 'igniteui-angular/grids/core';
    // import { IgxExcelExporterService, IgxExcelExporterOptions } from '@infragistics/igniteui-angular'; for licensed package
    ...
    
    public localData = [
      { Name: 'Eric Ridley', Age: '26' },
      { Name: 'Alanis Brook', Age: '22' },
      { Name: 'Jonathan Morris', Age: '23' }
    ];
    
    constructor(private excelExportService: IgxExcelExporterService) {
    }
    
    public exportButtonHandler() {
      this.excelExportService.exportData(this.localData, new IgxExcelExporterOptions('ExportedDataFile'));
    }
    
    

    If all went well, you should see an export button. When pressed, it will trigger the export process and the browser will download a file named "ExportedDataFile.xlsx" which contains the data from the localData array in MS Excel format.

    Customizing the Exported Content

    In the above examples the Excel Exporter service was exporting all available data. There are situations in which you may want to skip exporting a row or even an entire column. To achieve this you may hook to the columnExporting and/or rowExporting events which are fired respectively for each column and/or each row and cancel the respective event by setting the event argument object's cancel property to true.

    다음 예에서는 헤더가 "Age"이고 인덱스가 1인 경우 내보내기에서 열을 제외합니다.

    // component.ts
    
    this.excelExportService.columnExporting.subscribe((args: IColumnExportingEventArgs) => {
      if (args.header == 'Age' && args.columnIndex == 1) {
          args.cancel = true;
      }
    });
    this.excelExportService.export(this.igxGrid1, new IgxExcelExporterOptions('ExportedDataFile'));
    

    API References

    Excel 내보내기 서비스에는 아래에 나열된 몇 가지 API가 더 있습니다.

    그리드 Excel 내보내기:

    사용된 추가 구성요소:

    Additional Resources

    우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.