While working with the web applications, We often need to export data into pdf, excel, JSON, etc for generating invoices, reports and other analytical data to the user. I have already posted an article to generate PDF file in Angular Application
In this article, We will see how to export data in Angular application.
I assume you are familiar with Angular with Nodejs and Angular CLI installed into your system. Here, We will understand with creating a basic demo application
Run below command to create a new Angular application.
ng new angular-app
Once the new application created successfully, /now move to the project folder with the command cd ./angular-app
In the required task, we need to install xlsx npm module. Install it after typing below command over the terminal.
npm i xlsx --save
Here we will use a dummy list of users, In the real scenario, data will be fetched from the server.
Add below code in app.component.ts file.
userList = [
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz"
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna@melissa.tv"
},
{
"id": 3,
"name": "Clementine Bauch",
"username": "Samantha",
"email": "Nathan@yesenia.net"
},
{
"id": 4,
"name": "Patricia Lebsack",
"username": "Karianne",
"email": "Julianne.OConner@kory.org"
},
{
"id": 5,
"name": "Chelsey Dietrich",
"username": "Kamren",
"email": "Lucio_Hettinger@annie.ca"
}
]
Now we will update the template part. Put below code in app.component.html file with below code.
Finally, we are done with all the needed step, Run the app with below command over the terminal
npm start
In this article, We learn about the export of excel file in Angular application
I hope this article helped you to get in-depth knowledge about the topic. You can also find other demos/articles at Angular Sample Projects here to start working on enterprise-level applications.
Let me know your thoughts over email at pankaj.itdeveloper@gmail.com. I would love to hear them and If you like this article, share it with your friends.
Thank You!