Angular Data GridExportFile

Description

The ExportFile plugin lets you export table data as a string, blob, or downloadable CSV file.

See the export file demo for examples.

Example

import { AfterViewInit, Component, ViewChild } from "@angular/core";
import {
  GridSettings,
  HotTableModule,
  HotTableComponent,
} from "@handsontable/angular-wrapper";

`@Component`({
  selector: "app-example",
  standalone: true,
  imports: [HotTableModule],
  template: ` <div>
    <hot-table themeName="ht-theme-main" [settings]="gridSettings" />
  </div>`,
})
export class ExampleComponent implements AfterViewInit {
  `@ViewChild`(HotTableComponent, { static: false })
  readonly hotTable!: HotTableComponent;

  readonly gridSettings = <GridSettings>{
    data: this.getData(),
  };

  ngAfterViewInit(): void {
    // Access to plugin instance:
    const hot = this.hotTable.hotInstance;
    // Access to exportFile plugin instance
    const exportPlugin = hot.getPlugin("exportFile");

    // Export as a string
    exportPlugin.exportAsString("csv");

    // Export as a blob object
    exportPlugin.exportAsBlob("csv");

    // Export to downloadable file (named: MyFile.csv)
    exportPlugin.downloadFile("csv", { filename: "MyFile" });

    // Export as a string (with specified data range):
    exportPlugin.exportAsString("csv", {
      exportHiddenRows: true, // default false
      exportHiddenColumns: true, // default false
      columnHeaders: true, // default false
      rowHeaders: true, // default false
      columnDelimiter: ";", // default ','
      range: [1, 1, 6, 6], // [startRow, endRow, startColumn, endColumn]
    });
  }

  private getData(): any[] {
    // get some data
  }
}

Members

ExportOptions

Source code

ExportFile.ExportOptions : object

Properties

Name Type Default Description
[exportHiddenRows] boolean false Include hidden rows in the exported file.
[exportHiddenColumns] boolean false Include hidden columns in the exported file.
[columnHeaders] boolean false Include column headers in the exported file.
[rowHeaders] boolean false Include row headers in the exported file.
[columnDelimiter] string "," Column delimiter.
[range] string "[]" Cell range that will be exported to file.
[sanitizeValues] boolean | RegExp | function false Controls the sanitization of cell value.

Methods

downloadFile

Source code

exportFile.downloadFile(format, options)

Exports table data as a downloadable file.

Param Type Description
format string Export format type eg. 'csv'.
options ExportOptions Export options.

exportAsBlob

Source code

exportFile.exportAsBlob(format, options) ⇒ Blob

Exports table data as a blob object.

Param Type Description
format string Export format type eq. 'csv'.
options ExportOptions Export options.

exportAsString

Source code

exportFile.exportAsString(format, options) ⇒ string

Exports table data as a string.

Param Type Description
format string Export format type eq. 'csv'.
options ExportOptions Export options.

isEnabled

Source code

exportFile.isEnabled() ⇒ boolean

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit hook and if it returns true then the ExportFile#enablePlugin method is called.