Thanks for Sharing.
Drupal 7 Views Data Export Module
Share with Others
The Views Data Export Module provides an easy way to export your views data in many different formats (CSV, XLS, DOC, TXT, XML, etc).
In this episode you will learn:
- How to export Drupal 7 views data as a CSV file
- How to export Drupal 7 views data as an XLS file
- How the Drupal views page display is handled independently of what is actually exported in the Views data export
Thanks to Drupalize.me for sponsoring this episode of the Daily Dose of Drupal.
If you are new to views, you can check out our Drupal views module video.
Hello everyone and welcome to another Daily Dose of Drupal, today we’re on Episode Number 120 and today we’re going to be going over the Vies Data Export Module. The Views Data Export Module is a module that will allow you to export large amounts of data sets or data from your Views.
You can export them in CSV files, Microsoft Excel, Microsoft Doc, Text or XML and this is useful if you want to provide either yourself or users of your Drupal website the ability to export data from your various content types or anything that can be displayed using views.
Before we get started; as always I’m Shane Thomas, you can follow me on Twitter at smthomas3, you can also go to codekarate.com and sign up for the newsletter. As always or at least it has been recently … drupalize.me is today’s sponsor. If you haven’t check them out yet lease do so because they provide some great Drupal training videos along with J Query training and they have all different types of topics, a bunch of free videos so go ahead and give them a look and use CK20FEB as the coupon code and you get 20% off.
Let’s go ahead and get started; so I have the module already downloaded and installed on this test Drupal site, as you can see Views Data Export, I’m using the 7.x-3.O.Beta 6 version and it’s really pretty simple to get started. So I have a bunch of just added in default random content here using the Duval Generate Module so I have a bunch of articles.
I’m going to go ahead and create a View and we’re going to allow exporting of this view into a CSV in a Microsoft Excel format just so we can take a look at how that looks and how that works. So I’m going to create a new View, we’ll call this one Export Example and I’m going to show content of type article, we’ll allow it to create a page so we’ll go continue and edit and I’m going to select just to show fields here just to build out the very basic views so you can see if you have a view that you start with what you can then do.
I will go ahead and show it in a table format just to make it easier, there’s a title field, we’ll add the body field as well as the author UID and the path, the post and the NID just so we have some data that we can export. I’ll go ahead and leave … we’ll trim the body that keep it relatively small but you won’t have to of course, I’ll leave the rest of the stuff at the default and that should at least give us a starting point.
As you can see if you look down here you can see that the data is being dropped in to a table format, I’m going to give this a label so the title label will now show up down below and now you have your simple view that’s just a table format view, displays a title, the author user ID, a trimmed section of the body based on the number of characters, node ID, path and post-date.
So the goal is to allow users or yourself to export this data. Go ahead and save this and the next step is going to be adding a new display onto the this View and as you can see there’s a data export display that you can add onto this view so we’re going to go ahead and click that.
As soon as we do that you’ll see that it comes up with a new display, it has various formatting options so you can select CSV file, Doc, Text, XLS or XML. We’ll leave it at the CSV file for now, you can select Settings so you can have it set as a file or you can have it set as a feed. We’ll go ahead and say we want to provide it as a file, select the separator. A whole bunch of different options that you can look at, different character and codings, you can make use the first row as a header so you can look through those various options there and you can give this a path.
I’ll go ahead and say export example CSV, you can also attach it to the actual page. You want to make sure you attach it so you can actually see the link. You can select whether or not this should be batched and what this does is if you have a large amount of data you may want to go ahead and select to batch this and this is going to … instead of trying to download the entire chunk of data or all of the rows at one time it will export all of it into a CSV file and in this case it’s going to batch it up into various segments so it’s going to make it less memory intensive and it’s just going to be better especially for larger data sets.
For this case I’m not going to use a batch because it’s not over a thousand rows, it’s relatively small like 300 so we should be fine but just keep in mind that’s an important setting especially if you’re exporting large amounts of data. So I’m going to go ahead and save this and I will click here to view the page, you can see the data is here and you’ll also notice this link at the bottom.
So this is what this Views Display that we added for Data Export does; it adds this little icon here, I click this and you’ll notice that it download this CSV file, I click to open it and depending on what type of spreadsheet software or how you generally open your CSV files on your system it’s going to open it up. As you can see it’s exported the data, you’ll notice it’s only showing me 10 items even though I have much more than 10 items.
So what I will be able to do here is if I come back into this view I can simply edit the view, come into the Data Export and … well actually we’ll come into the page instead of a page here and we can go ahead and select 0 here so it’s going to show all the items, we’ll save that and well come back and view the page. Now you can see it’s a much longer page, I open up the CSV, actually need to set the pager on that display. So it actually separates out the two displays so the Page Display is not necessarily going to be exactly the same as the Export Display.
So you can display set number of items on the first … the actual page but you can actually export a different number of items. So here’s where I can actually select what shows up in the Data Export versus the page show up how much it actually going to display when you’re viewing the page. So right now I set this to show all on the page but the data export is still set to 10 items. Just keep in mind that these can be set independently of each other.
Now as soon as I change this to 0 I can go ahead and re-export and it is going to export all the rows that I have in the database rather than just the first 10. So now when I open this up I will see much more than 10, as you can see there’s about 300 or so in there. So we’re going to go ahead and just show how you can export in one more formats and then you should be able to take the idea and run with it and use it to export any different type of data that you may need.
So I’m going to add another Data Export Display, again if you need to change a number of items you can set that to 0 to show all items, you can also select this item or this second options here to just display all items, either way will work, we’re going to change this to in XLS file so this would be an Excel format, you can provide it as a file if you want or as a feed instead of file for download.
Now we can go ahead and save this, actually I have to make sure I have to give it a path first of course so we’re going to give it a Views Export XLS, make sure we attached it to our page, save it and we should be able to come back to the main page and see another icon down at the bottom. So now you can see I can export this either a CSV or an XLS file, I can add as many different data export views display onto this views I need to so I can have a text file or a doc or an xml and I can of course just click it and export to a file so I have an easy way to download the data that’s being displayed in the view.
Keep in mind that even in the columns don’t have to necessarily have to be identicals. So if I wanted add an additional column to one of these exports I can do that and it will show up in the export but doesn’t necessarily have to show up in the View. So if for instance in this xls I also wanted to add whether or not it was published, I will actually … let me remove that for a second, I will make sure I override so it’s only going to be adding it to this display and now I’ll find the Publish option again.
So as you can see on this Display Only there’s a Publish option on the page, if I click on page there is no Publish option so I’ll save this, come back to the View itself. You’ll notice there is no Publish column however if I come down to the bottom and export to xls and open this up you’ll notice that there is a Publish column. So just keep in mind as we ran into the first case with the pagers everything is independent of each other because there’s just different Views display so what you display on the page doesn’t necessarily have to be identical in the number of columns or the number of rows displayed when you actually export the data using one of the various data export formats.
So really it’s pretty simple, it’s very easy way to export your data off your Drupal site using Views so go ahead and try it out, I’m sure you can find many uses for it on your Drupal sites. Thanks again to drupalize.me for sponsoring this episode of the Daily Dose of Drupal and thanks for watching, we’ll see you next time.