views:

52

answers:

1

Hi experts,

I need to export to excel and csv format in jasper reports. for excel I tried by using JRXlsExporter api)but it is not exporting, the thing is with "save and cancel" popup window is coming with file type unknown..

 file type like "getReportDetail.do"

where "getReportDetail.do" is "path" attribute in "action" element of struts config xml.i am calling this "getReportDetail.do" by clicking html button to invoke "action class" to export excel.

i am setting parameter like below

reportExporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint); 
reportExporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, reportStream); 

reportExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); 
reportExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
reportExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
reportExporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);          

where reportStream is object of "ByteArrayOutputStream()".

reportExporter is "JRXlsExporter" object..

contenttype is "response.setContentType("application/xls");"

any idea why it is happening?

A: 

Try setting the following headers:

Content-Type: application/vnd.ms-excel
Content-Disposition: attachment; filename=report.xls
yshalbar