Allow for specifying the response contenttype and filename
Posted: 25 Jun 2009, 21:02
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:
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.
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+"\"");
}
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.