Allow for specifying the response contenttype and filename

Post Reply
mathwizard
Posts: 2
Joined: 26 Apr 2009, 13:04

When developing custom reports, it's sometimes good to have a direct Excel export of something. This is actually incredibly easy, as a HTML table will be automatically interpreted by Excel and OpenOffice as a WorkSheet. So I added the possibility to specify a Content Type and Filename for a response of a report.

The programatic change is to ReportServlet.java:

Code: Select all

String contentType = null;

String filename = null;

contentType = request.getParameter("CT");

filename = request.getParameter("FILE");

if(contentType != null) {

    response.setContentType(contentType);

}



if(filename != null) {

    response.setHeader("Content-Disposition", "attachment; filename=\""+filename+"\"");

}
It adds to possible URL parameters:

CT - Content type (for excel use application/ms-excel)
FILE - what is going to be the filename that will show up in your download dialog (e.g. myreport.xls)

Hope it will help. If it makes into the official viewer, even better.
Last edited by mathwizard on 26 Jun 2009, 12:57, edited 1 time in total.
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Thanks for posting this. Great work.
Previously, I'd created a specific "export to CSV" report through a simple XSLT. This looks really interesting.

Jonathan
Essential Project Team
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Just to let you know that I have just brought this code into the core Essential Viewer code. Thanks again for your contribution - it works a treat.

Jonathan
Essential Project Team
Post Reply