Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { LabService } from '@services'
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- public xl;
- constructor(public lab: LabService) {
- }
- export() {
- this.lab.export().subscribe((res:any) => {
- this.xl = JSON.stringify(res)
- })
- }
- exportTableToExcel(tableID, filename = ''){
- var downloadLink;
- var dataType = 'application/vnd.ms-excel';
- var tableSelect = document.getElementById(tableID);
- var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
- filename = filename?filename+'.xls':'excel_data.xls';
- downloadLink = document.createElement("a");
- document.body.appendChild(downloadLink);
- if(navigator.msSaveOrOpenBlob){
- var blob = new Blob(['\ufeff', tableHTML], {
- type: dataType
- });
- navigator.msSaveOrOpenBlob( blob, filename);
- }else{
- downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
- downloadLink.download = filename;
- downloadLink.click();
- }
- }
- ngOnInit(): void {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement