Excel Export (xls/xlsx) Service.
npm install @slickgrid-universal/excel-export





@slickgrid-universal/excel-exportSimple Export to Excel Service, which requires excel-builder-vanilla external dependency, which allows exporting your grid data as .xls or .xlsx files.
- excel-builder-vanilla to build and export to Excel.
You can also use nearly all Excel-Builder-Vanilla options, see their Excel-Builder-Vanilla - Documentation and also take a look at Slickgrid-Universal Excel Export - Documentation on how to use both.
externalResources as shown below.##### ViewModel
``ts
import { ExcelExportService } from '@slickgrid-universal/excel-export';
export class MyExample {
initializeGrid {
this.gridOptions = {
enableExcelExport: true,
// you need to register it as an external resource
externalResources: [new ExcelExportService()],
// set any options
excelExportOptions: {
sanitizeDataExport: true
},
}
}
}
`
If you wish to reference the service to use it with external export button, then simply create a reference while instantiating it.
`ts
import { ExcelExportService } from '@slickgrid-universal/excel-export';
export class MyExample {
excelExportService: ExcelExportService;
constructor() {
this.excelExportService = new ExcelExportService();
}
initializeGrid {
this.gridOptions = {
enableExcelExport: true,
excelExportOptions: {
sanitizeDataExport: true
},
externalResources: [this.excelExportService],
}
}
exportToExcel() {
this.excelExportService.exportToExcel({ filename: 'export', format: 'xlsx' });
}
}
`
(it compresses the data before sending it to the browser) and for better performance it uses Web Workers and for that reason you might need to adjust your CSP rules. You simply need to add a CSP rule to avoid the error worker-src 'self' blob:;`html
content="default-src 'self'; ...other rules... worker-src 'self' blob:;" />
``