Angular -Download Data in Excel format

Angular -Download Data in Excel format

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

No alt text provided for this 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 :

No alt text provided for this image

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.



要查看或添加评论,请登录

Sougandika L的更多文章

  • Lifecycle Methods in Functional components

    Lifecycle Methods in Functional components

    Lifecycle refers to the series of phases that a React component goes through from its creation, rendering and eventual…

  • Are you excited to know about Event Flow in Javascript ??

    Are you excited to know about Event Flow in Javascript ??

    Order in which event triggered on DOM nodes is called event flow. There are 2 types of events: 1.

  • Angular 18 feature - Zoneless Change Detection

    Angular 18 feature - Zoneless Change Detection

    One of the most significant changes is the introduction of zoneless change detection. Reason : To avoid unnecessary…

  • Difference between Subject and Observable

    Difference between Subject and Observable

    1.Subject can be provider as well as consumer.

  • Why do we need package.json

    Why do we need package.json

    Most of us are concerned or focused on the place where we write our code, whether it might be styling (css) or…

  • SIGNAL in Angular

    SIGNAL in Angular

    With Change detection, incase of any change in one of the components, it check for all the components and then render…

    1 条评论
  • Creating Reusable Components in Angular

    Creating Reusable Components in Angular

    Lets start with a basic button Here in the image we could see 3 different buttons with different names, different…

    3 条评论
  • Reactive forms in Angular

    Reactive forms in Angular

    Angular provides 2 ways to work with forms – 1. Template driven forms 2.

  • Why Array ? Its declaration in Javascript

    Why Array ? Its declaration in Javascript

    Array is a special variable which holds more than one value at a time. It stores the homogenous elements.

  • Scope: What does it exactly mean?

    Scope: What does it exactly mean?

    Hello everyone, This is Sougandika. Do you want to know what is scope? Be with me till the end and I am sure that this…

社区洞察

其他会员也浏览了