Entity view (Content)

Export Data From Views to CSV File

By fyu
Feb. 17, 2015

It is sometimes useful to be able to save our view results into a document to allow non-technical people to manipulate the data. Other than writing custom code, there is an easy and fast way to accomplish this: using the module Views Data Export. It provides the functionality of taking the (filtered) results of a view and export them into a data file (CSV, XML or other types of data file). As the module name tells you, you will need to first download and enable the module Views and Views UI.

To start, create a new view. The display can be a block or page, depending on your needs. The format of the results doesn't have a big impact on the results to be exported, but I usually prefer table, because it looks more organized. Then, select the fields to be displayed in the results and select also the fields under filter criteria to be or not to be used as exposed filters. Below, I have created an example of a view that would display a list of guests, and the fields used are First Name and Last Name.

When you've got everything, test your view to make sure that it works. After verification, you can add a display of type Data Export.

 

Select format "CSV File", it should be the default format. If you want to export the same results as displayed on your page / block, re-use the same displayed fields and filter criteria. Give the display a path. To add the CSV export functionality to the page view, go to Attach to under Data Export Settings and select Page or the name you have given to your page display. Notice the CSV button below the results.

Now, test it. Enter some values in the filters, get the results and click on the CSV button. You will see that the new CSV file contains the same data as your view results. And voilà, you are now able to export your view results into a CSV file.

Post Tags: