Skip to content

Instantly share code, notes, and snippets.

@nyx-rattapoom
Created March 25, 2018 20:06
Show Gist options
  • Save nyx-rattapoom/105c614266d6365ca75ec342254e4897 to your computer and use it in GitHub Desktop.
Save nyx-rattapoom/105c614266d6365ca75ec342254e4897 to your computer and use it in GitHub Desktop.
angular2+ xlsx export
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