How to Create excel file and download it or convert into base64 string

How to Create excel file and download it or convert into base64 string

1).First Install Following packages from Node module
1).npm install exceljs
page Url:https://www.npmjs.com/package/exceljs
2).npm install file-saver --save
page Url:https://www.npmjs.com/package/file-saver
Code Writing:-


import * as Excel from 'exceljs/dist/exceljs';
import * as FileSaver from 'file-saver';
import { Injectable } from '@angular/core'; @Injectable({
providedIn: 'root', }) export class HeroService { constructor() { }
public generateExcel(paramData: any, _ReferenceNo, IsSend = false): any { return new Promise((resolve, reject) => { if (IsSend) { return this.workbook.xlsx.writeBuffer({ base64: true }).then((data) => { const itemdata = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); const reader = new FileReader(); reader.readAsDataURL(itemdata); reader.onloadend = function () { return resolve(reader.result.toString().replace('data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,', '')); } }); } else { this.workbook.xlsx.writeBuffer().then((data) => { const blob = new Blob([data], { type: EXCEL_TYPE }); FileSaver.saveAs(blob, _ReferenceNo ? _ReferenceNo : 'temporary' + EXCEL_EXTENSION); return resolve(data); }); } }); }
}
Calling Method to component:- 


this.pdfService.generatePDF(this.trademodel, true, false).then(resp=>{
postJson.PdfString=resp;
});





No comments:

Post a Comment

Thank You For Your Great Contribution

Featured Post

How to integrate okta with react / Implementing Okta authentication in a React app

 How to integrate okta with react /  Implementing Okta authentication in a React app for demo please follow  my git repo 1).Before starting ...

Popular Posts