I've looked at some plugins but no success. I tried Export Plugin 1.6 as well but the view doesn't recognize r:.. and export:.. tags. What is the best way to export rows of data from postgresql database into an excel file from a click of a button? Thank you.
-
1Have a look at the mailinglist plug in https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/controllers/grails/plugin/mailinglist/core/MailingListController.groovy I got the export service to work and it was working under grail 2.4. I made the buttons up myself in the gsp – V H Dec 03 '15 at 21:57
-
1http://grails.1312388.n4.nabble.com/Novice-needs-help-for-simple-CSV-export-td3496037.html fine example of doing it all yourself – V H Dec 03 '15 at 22:28
-
@vahid Thank you. I got it to work with the csv file following the code from grails.1312388.n4.nabble.com/… I will have to work again with Export Plugin once I work "Can't find the plugin issue I mention on the bottom of this question. – monty_bean Dec 04 '15 at 16:55
-
1did you try the plugin above on a test site ? try it and see. It works under 2.4 you should be able to import some csv file and then use the export feature to export specific listing on the screen. https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingList/_listing.gsp#L30-L46 The r:require relies on resources from 2.4 it changed to assets, you can install resources or just look at how I hacked it in manually as outlined in the link to the gsp. – V H Dec 08 '15 at 12:02
3 Answers
you could create a gsp which renders a .csv
-file and set the content-type
of the response to application/vnd.ms-excel
within the controller.
that's the easiest way, but you will not be able to control the format of cells.
Apache POI - as mentioned by Abincepto - is another solution which is more complex but gives you full control over the generated excel file

- 10,742
- 10
- 69
- 126
Did you try directly with apache poi ?
From the website:
The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.
EDIT: Here is a tutorial: Read / Write Excel file in Java using Apache POI and a quick guide
EDIT2: I just found another link using Grails that could help you. The example use another library: jexcelapi

- 1,016
- 8
- 13
-
Can you explain to me in a detail please? I'm a newbie and I went to apache poi site and didn't quite understand. So what do I do after I download the file? Thanks. – monty_bean Dec 03 '15 at 20:28
-
What are you trying to do? Serve up the excel file as a download? Write it out to the file system? – BZ. Dec 03 '15 at 20:56
-
I just added two links. It's full of examples. I hope it is going to help you. In details, Apache POI is an API. With this API, you can create, read or manipulate Microsoft Documents. Try the first examples, and I think you are going to understand really fast how it works. – Abincepto Dec 03 '15 at 21:32
-
@Abincepto Thank you. I am working my way through this. This is more than my skill level at the moment but I will get through. – monty_bean Dec 04 '15 at 17:04
-
I never tried the export plugin, but I think the r:-tag needs the resources plugin. Did you try to install this plugin ? (I don't know if it is a good thing to use both asset-plugins and resources plugins. On my side, I always remove the asset plugins). – Abincepto Dec 04 '15 at 21:52
The export plugin is dependent on the resources plugin. You can add the resources plugin and try again. I use resources 1.2.8. Also you need to add this to your dependencies:
dependencies {
............
// Needed for the export plugin?
compile 'commons-beanutils:commons-beanutils:1.8.3'
plugins {
............
runtime ":resources:1.2.8"

- 1,219
- 8
- 13
-
I've added the following to my BuildConfig.groovy file but I keep getting this error. Could not find artifact org.grails.plugins:export:jar:1.6 in grailsCentral (https://repo.grails.org/grails/plugins) repositories { ... mavenRepo "http://repo.grails.org/grails/core" ... } dependencies { ... compile "org.grails.plugins:export:1.6" compile 'commons-beanutils:commons-beanutils:1.8.3' ... } plugins { ... runtime ":resources:1.2.8" ... } What should I do to get the plugin? – monty_bean Dec 04 '15 at 17:01