---
title: "How can I export data CSV on Angular?"  
description: "How can I export data CSV on Angular?"  
author: "Steilla Mitchel"  
published: 2023-08-24  
updated: 2023-08-26  
canonical: https://www.mindstick.com/forum/159654/how-can-i-export-data-csv-on-angular  
category: "angular js"  
tags: ["angular js", "angularjs filter"]  
reading_time: 2 minutes  

---

# How can I export data CSV on Angular?

How can I [export data](https://www.mindstick.com/forum/382/how-to-import-and-export-data-in-sql-server-from-different-file-format) [CSV](https://www.mindstick.com/blog/257/write-data-in-excel-csv-and-xml-file-using-c-sharp) on [Angular](https://www.mindstick.com/articles/13081/advantages-disadvantages-of-angularjs-is-that-ideal-for-your-project)?

## Replies

### Reply by Aryan Kumar

There are a few ways to [export](https://www.mindstick.com/articles/12966/a-guide-to-export-pallets) [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) to CSV on Angular. One way is to use the `FileSaver` service. The `FileSaver` service can be used to create and save a file on the user's computer.

To export data to CSV using the `FileSaver` service, you can follow these steps:

1. Import the `FileSaver` service into your Angular application.
2. Create a function that will export the data to CSV. The function should take an array of data as its input and return a promise.
3. In the function, create a new `Blob` object from the array of data.
4. Use the `FileSaver` service to save the `Blob` object to the user's computer.

Here is an example of a function that can be used to export data to CSV using the `FileSaver` service:

```plaintext
export function exportDataToCSV(data: any[]): Promise<void> {
  const blob = new Blob([data], { type: 'text/csv' });
  const fileName = 'data.csv';
  const fileSaver = new FileSaver();

  fileSaver.save(blob, fileName);
}
```

Another way to export data to CSV on Angular is to use the `csv-export` library. The `csv-export` library is a third-party library that can be used to export data to CSV.

To export data to CSV using the `csv-export` library, you can follow these steps:

1. Install the `csv-export` library in your Angular application.
2. Import the `csv-export` module into your Angular application.
3. Create a function that will export the data to CSV. The function should take an array of data as its input and return a promise.
4. In the function, use the `csv-export` library to export the data to CSV.

Here is an example of a function that can be used to export data to CSV using the `csv-export` library:

```plaintext
import { Component, OnInit } from '@angular/core';
import { csvExport } from 'csv-export';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  data = [
    {
      id: 1,
      name: 'John Doe',
      email: 'johndoe@example.com'
    },
    {
      id: 2,
      name: 'Jane Doe',
      email: 'janedoe@example.com'
    }
  ];

  ngOnInit() {
  }

  exportDataToCSV() {
    csvExport(this.data, 'data.csv');
  }
}
```


---

Original Source: https://www.mindstick.com/forum/159654/how-can-i-export-data-csv-on-angular

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
