0

I am trying to save the Jasperreport into an excel file. But while we generate the excel file only the webpage content is saved to the excel file. The Jasper report content is not saved to the excel file.

public void generateXLSOutput(JasperPrint jasperPrint, HttpServletResponse resp) throws IOException, JRException {
        String reportfilename = "SampleExcelReport" + ".xls";
        @SuppressWarnings("deprecation")            
        JRXlsExporter exporterXLS = new JRXlsExporter();                 
        exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
        exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, resp.getOutputStream());
        resp.setHeader("Content-Disposition", "inline;filename=" + reportfilename);
        resp.setContentType("application/vnd.ms-excel");

        exporterXLS.exportReport();
}
Alex K
  • 22,315
  • 19
  • 108
  • 236
Bibin Jose
  • 563
  • 4
  • 11
  • 19
  • Remove the deprecated code http://stackoverflow.com/a/33890101/5292302 and explain better what is actually happening, I can't understand "only the webpage content is saved to the excel file", which webpage content?, screen shot? – Petter Friberg Jun 18 '16 at 21:04
  • @Alex K : I am generating the excel file from a web page. The web page contains the options to generating the report in excel, PDF and Html format. I choose the option excel format and then press the generate button, The excel file will be generated. But the content of the excel file is the above html file content. That is the options PDF/Excel?HTMl and button name etc. – Bibin Jose Jun 19 '16 at 07:32
  • @Alex K : I used the code in your comment "stackoverflow.com/a/33890101/5292302 " but same thing happens no chnage in the excel file content. – Bibin Jose Jun 19 '16 at 07:35
  • Check [this answer which deals with headers send too late](http://stackoverflow.com/questions/6520231/how-to-force-browser-to-download-file/6520353#6520353) just to make sure. – tobi6 Jun 20 '16 at 07:23

0 Answers0