Created
March 25, 2018 20:06
-
-
Save nyx-rattapoom/105c614266d6365ca75ec342254e4897 to your computer and use it in GitHub Desktop.
angular2+ xlsx export
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 { Injectable } from '@angular/core'; | |
import * as XLSX from 'xlsx'; | |
const EXCEL_EXTENSION = '.xlsx'; | |
@Injectable() | |
export class ExcelService { | |
constructor() { } | |
public exportAsExcelFile(json: any[], excelFileName: string): void { | |
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json); | |
const workbook: XLSX.WorkBook = XLSX.utils.book_new(); | |
XLSX.utils.book_append_sheet(workbook, worksheet, 'Student'); | |
XLSX.writeFile(workbook, excelFileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment