@slickgrid-universal/excel-export

Excel Export (xls/xlsx) Service.

Usage no npm install needed!

<script type="module">
  import slickgridUniversalExcelExport from 'https://cdn.skypack.dev/@slickgrid-universal/excel-export';
</script>

README

License: MIT TypeScript lerna--lite npm npm

Actions Status Cypress.io jest codecov

Excel Export Service

@slickgrid-universal/excel-export

Simple Export to Excel Service that allows to exporting as .xls or .xlsx.

Internal Dependencies

External Dependencies

This package requires excel-builder-webpacker which itself requires jszip and lodash, the later not being a small lib, so make sure that you are fine with the bundle size. For our use case, the extra bundle size is totally worth the feature.

Installation

Follow the instruction provided in the main README, you can see a demo by looking at the GitHub Demo page and click on "Export to Excel" from the Grid Menu (aka hamburger menu).

Usage

In order to use the Service, you will need to register it in your grid options via the registerExternalResources as shown below.

ViewModel
import { ExcelExportService } from '@slickgrid-universal/excel-export';

export class MyExample {
  initializeGrid {
    this.gridOptions = {
      enableExcelExport: true,
      excelExportOptions: {
        sanitizeDataExport: true
      },
      registerExternalResources: [new ExcelExportService()],
    }
  }
}

If you wish to reference the service to use it with external export button, then simply create a reference while instantiating it.

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
      },
      registerExternalResources: [this.excelExportService],
    }
  }

  exportToExcel() {
    this.excelExportService.exportToExcel({ filename: 'export', format: FileType.xlsx });
  }
}