views:

55

answers:

2

Hello: My list.gsp is divided into two, the top part is like a search filter, and the bottom part is the regular list that is provided by Grails

I have a template _list.gsp in my list.gsp. And I wanna create a button to make that _list.gsp template a MS Excel file.

But I want only the template to be on the Excel file. Not the rest of the page

How can I do this in the simplest and direct way possible?? Thank you!

A: 

Try this quite dirty trick in your index method:

response.setHeader( 'Content-Disposition', 'attachment;filename=list.xls' )

Explanation: the trick is that an HTML page renamed as *.xls can be read by office software suites. What you're doing is telling the browser to download a file with that name, instead of navigating to a regular HTML file. If you want to use this in a button, you should proceed as with any HTML generating page, and then add this header to the response. response is global to actions in Grails controllers.

mrrtnn
What after that?? I wanna export it to Excel when clicking on a button.
fgualda87
I added the explanation.
mrrtnn
I'm sorry, I'm a little new to Grails, could you give me an example?? Like whenever I click the button it should download the .xls file but I still need to be able to do some other things in the page, I have a search filter, and I need to be able to send the search results to a .xls file
fgualda87
A: 

you can also take a look at the export plugin if you want to export the list to excel format

http://www.grails.org/plugin/export

Aaron Saunders
I installed the Export plugin but it doesn't seem to be working right
fgualda87
@fgualda87 what kind of problems
Aaron Saunders
Executing action [list] of controller [density.DensityController] caused exception: No such property: response for class: java.lang.String
fgualda87