Skip to content

Instantly share code, notes, and snippets.

@HalitTalha
Created April 9, 2020 20:45
Show Gist options
  • Save HalitTalha/447aef9ed71da820048db82ef221aa8f to your computer and use it in GitHub Desktop.
Save HalitTalha/447aef9ed71da820048db82ef221aa8f to your computer and use it in GitHub Desktop.
Simple implementation of nativetable exporting for Angular Material Tables. SheetJs is employed
import { Component, ViewChild, ElementRef } from '@angular/core';
import * as XLSX from 'xlsx';
export class AppComponent {
@ViewChild('TABLE', { static: true }) table: ElementRef;
exportTable() {
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement);
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, 'Exported_File.xlsx');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment