Este serviço tem como objetivo abstrair a criação de arquivos XLSX a partir de dados JSON, ideal para extração de dados.
Arquivos XLSX podem ser estilizados com cores de fundo e fonte, além de serem protegidos por senha e ter o cabeçalho normalizado.
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CatUiModule } from '@catrx/ui';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [CatUiModule.forRoot(environment, {
xlsxConfig: {
headerBackgroundColor: '#212121',
headerFontColor: '#f1f1f1',
normalizeHeader: true,
password: '123'
}
}), AppRoutingModule],
bootstrap: [AppComponent],
})
export class AppModule {}
<cat-toolbar [config]="getToolbarInfo()">
<nav buttons>
<button (click)="generateXLSXFile()" class="btn btn-primary btn-sm">
Gerar Arquivo .xlsx
</button>
</nav>
</cat-toolbar>
import { Component } from '@angular/core';
import { CatComponentBase } from '@catrx/ui/common';
import { CatXlsxService } from '@catrx/ui/utils/xlsx';
@Component({ templateUrl: './page.xlsx.component.html' })
export class PageXlsxComponent extends CatComponentBase {
constructor(private xlsxService: CatXlsxService) {
super();
}
public generateXLSXFile() {
this.xlsxService.convertJsonToXlsx(
[
{
sheetName: 'Felinos',
json: [
{ name: 'Jimmy', lastname: 'Hendrix' },
{ name: 'Fred', lastname: 'Mercury' },
{ name: 'John', lastname: 'Snow' },
],
},
{
sheetName: 'Cães',
json: [
{ name: 'Jimmy', lastname: 'Hendrix' },
{ name: 'Fred', lastname: 'Mercury' },
{ name: 'John', lastname: 'Snow' },
],
},
],
'Lista de Pets'
);
}
}
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { CatToolbarModule } from '@catrx/ui/toolbar';
import { PageXlsxComponent } from './page-xlsx.component';
import { PageXlsxRoutingModule } from './page-xlsx.routing.module';
@NgModule({
declarations: [PageXlsxComponent],
imports: [CommonModule, CatToolbarModule, PageXlsxRoutingModule],
})
export class PageXlsxModule {}