Created
April 9, 2020 20:45
-
-
Save HalitTalha/447aef9ed71da820048db82ef221aa8f to your computer and use it in GitHub Desktop.
Simple implementation of nativetable exporting for Angular Material Tables. SheetJs is employed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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