Export/Import content type to Excel or CSV

Topics: Customizing Orchard, Writing modules
Jan 20, 2014 at 6:56 PM

Is there any module out there or has anyone written code, that exports/import a content type/custom forms data to/from excel or CSV?

If not, is anyone else looking for something like this, or is it just me?
Jan 21, 2014 at 9:50 PM
@rudolphk we've actually done this for the Outercurve services site (the relevant part of the site is only accessible for staff) for managing our contributor license agreements. The code for our site is at https://github.com/ericschultz/outercurve-orchard and the relevant class which exports from our CLA content type to CSV is at: https://github.com/ericschultz/outercurve-orchard/blob/master/src/Orchard.Web/Modules/Outercurve.Projects/Services/CLAToOfficeService.cs The code is certainly specialized to our CLA type and only handles exporting but it should give you something to work from. )

We actually at one point had Excel integration but due to the non-open source license on Open XML SDK for Office and since CSV can be easily opened in any spreadsheet application, I decided to remove that feature. It's a lot easily to implement in CSV too because the Open XML SDK is not the most intuitive library.

An older version of this code shows how you might use the Open XML SDK if you were set on writing native excel files (https://github.com/ericschultz/outercurve-orchard/blob/bd3a52177cbbcc5415a5cd023c94fbf742d6969f/src/Orchard.Web/Modules/Outercurve.Projects/Services/CLAToOfficeService.cs). That said, if you wanted to include this module in Orchard by default, it really shouldn't depend on a non-open source component like the Open XML SDK.

Marked as answer by rudolphk on 1/21/2014 at 10:35 PM
Jan 22, 2014 at 5:35 AM
Thanks Eric

I've forgot about the licensing requirement. The code sample will definitely help, but I would like to do something a bit closer to the current XML export, where it dynamically export any content type.
Feb 5, 2014 at 5:34 PM
I've created a module for the first part of exporting a content type to CSV: