Angular -Download Data in Excel format
Sougandika L
Immediate Joiner ll Serving Notice Period ll Software Developer at People Tech Group private Ltd Il ANGULAR l TYPESCRIPT l KENDOUI l NGRX l REDUX l HTML l SCSS I CSS l BOOTSTRAP
Hello everyone,
One of the most common usecases now a days is printing the data. In this article we will be understanding how to print the data in the excel format on click.
Step1 : Open the terminal and run the following command to install
npm i?ngx-csv
Step 2: In the particular component where the download needs to be done. In that particular components ts file, import the following
import?{?ngxCsv?}?from?'ngx-csv/ngx-csv';
Step 3: For suppose if it needs to be downloaded on click of a button
<button mat-icon-button color="accent" (click)="printExcelFormat()">Click to download</button>
Step 4: Write below code as shown in the image
Code above is explained below:
new ngxCsv(data,?filename,?options) => It means creating new object. Where data --> Data to be printed in file, filename --> Name of the file to be shown after download, options --> Like already declared in the above image.
In options : noDownload is set to false because the file needs to be downloaded, title is the title to be displayed in the downloade file, headers are the name of the columns
Step 5: On click the file is downloaded with the name mentioned. If opened it will be shown as :
Hope you learnt something new after reading my article.
Thank you for your time.
I will be back again with a different article
Sougandika L.