Angular Pivot Grid Export to Excel Service
The Excel Exporter service can export data to excel from the IgxPivotGrid. The data export functionality is encapsulated in the IgxExcelExporterService
class. To trigger the process, you need to invoke the IgxExcelExporterService
's export
method and pass the IgxPivotGrid component as the first argument.
Angular Excel Exporter Example
Exporting Pivot Grid's Data
Para começar a usar o IgniteUI Excel Exporter, primeiro importe o IgxExcelExporterService
arquivo app.module.ts e adicione o serviço à providers
matriz:
// app.module.ts
import { IgxExcelExporterService } from 'igniteui-angular';
// import { IgxExcelExporterService } from '@infragistics/igniteui-angular'; for licensed package
@NgModule({
providers: [ IgxExcelExporterService ]
})
export class AppModule {}
Note
Na v12.2.1 e posterior, os serviços de exportador são fornecidos na raiz, o que significa que você não precisa mais declará-los nos provedores AppModule.
Para iniciar um processo de exportação, você pode usar o manipulador de um botão no modelo do seu componente.
<igx-pivot-grid #pivotGrid [data]="localData" [pivotConfiguration]="pivotConfig"></igx-pivot-grid>
<button (click)="exportButtonHandler()">Export IgxPivotGrid 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 export
method and pass the IgxPivotGrid component as first argument.
Aqui está o código que executará o processo de exportação no arquivo datilografado do componente:
// component.ts
import { IgxExcelExporterService, IgxExcelExporterOptions } from 'igniteui-angular';
import { IgxPivotGridComponent } from 'igniteui-angular';
@ViewChild('pivotGrid') public pivotGrid: IgxPivotGridComponent;
constructor(private excelExportService: IgxExcelExporterService) {
}
public exportButtonHandler() {
this.excelExportService.export(this.pivotGrid, new IgxExcelExporterOptions('ExportedDataFile'));
}
If all went well, you should see the IgxPivotGrid component and a button under it. When pressing the button, it will trigger the export process and the browser will download a file named "ExportedDataFile.xlsx" which contains the data from the Pivot Grid component in MS Excel format.
Note
Expand/collapse indicators in Excel are shown based on the hierarchy of the last dimension of the Pivot Grid.
Note
The exported Pivot Grid will not be formatted as a table, since Excel tables do not support multiple row headers.
Customizing the Exported Content
Nos exemplos acima, o serviço Exportador do Excel estava exportando todos os dados disponíveis. Há situações em que você pode querer pular a exportação de uma linha ou até mesmo de uma coluna inteira. Para conseguir isso, você pode conectar os columnExporting
eventos e/ou rowExporting
que são disparados respectivamente para cada coluna e/ou cada linha e cancelar o respectivo evento definindo a propriedade do objeto de cancel
argumento de evento como true
.
The following example will exclude all columns from the export if their header is "Amount of Sale":
// component.ts
this.excelExportService.columnExporting.subscribe((args: IColumnExportingEventArgs) => {
if (args.header == 'Amount of Sale') {
args.cancel = true;
}
});
this.excelExportService.export(this.pivotGrid, new IgxExcelExporterOptions('ExportedDataFile'));
When you are exporting data from the Pivot Grid component, the export process takes in account features like row filtering and column hiding and exports only the data visible in the Pivot Grid. You can configure the exporter service to include filtered rows or hidden columns by setting properties on the IgxExcelExporterOptions
object.
Known Limitations
Limitação | Descrição |
---|---|
Tamanho máximo da planilha | O tamanho máximo da planilha com suporte no Excel é de 1.048.576 linhas por 16.384 colunas. |
Estilo de célula | O serviço exportador do Excel não oferece suporte à exportação de um estilo personalizado aplicado a um componente de célula. Nesses cenários, recomendamos o uso da Biblioteca do Excel. |
API References
O serviço Exportador do Excel tem mais algumas APIs para explorar, listadas abaixo.
Componentes adicionais que foram usados: