Jasper Reports 5 to 6 Methods obsolete

4

I created some reports through TIBCO Jaspersoft® Studio - Visual Designer for JasperReports and I'm using the lib below in my project.

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.0.0</version>
</dependency>

In previous versions I was using JRXlsExporter but some methods are obsolete and I did not find the new form in the official documentation (or I did not know how to look or it really was not updated).

Example:

   JRXlsExporter exporter  = new JRXlsExporter(); 
   response.setHeader("Content-Disposition", "attachment;    filename=PONTOS_DE_VENDA.xls");
   response.setContentType("Content-type: application/vnd.ms-excel"); //DEPRECATED
   exporter.setParameter(JExcelApiExporterParameter.JASPER_PRINT, jasperPrint); //DEPRECATED
   exporter.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM,  response.getOutputStream()); //DEPRECATED

Has anyone used this new version yet? Or where I find some example of usage.

    
asked by anonymous 16.12.2014 / 13:34

2 answers

5

According to the Javadoc class JRXlsExporter :

setParameter - > Replaced by setExporterInput(ExporterInput) , setConfiguration(ExporterConfiguration) , setConfiguration(ReportExportConfiguration) and setExporterOutput(ExporterOutput) .

I do not know what kind your object is response (if it is ServletResponse method setContentType does not seem to have been discontinued).

More information : SOen - JasperReports 5.6: JRXlsExporter.setParameter is deprecated

    
16.12.2014 / 15:17
1

In the end I came to this code, with Anthony Accioly's response just above:

        JRXlsExporter exporter  = new JRXlsExporter(); 
        SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
        configuration.setOnePagePerSheet(false);
        ......
        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream()));
        exporter.setConfiguration(configuration);
        exporter.exportReport();

In this case I had to change the exporter.setParameter to the SimpleXlsReportConfiguration that I can mount the same configuration that I used in the exporter. Visually it got even more elegant.

    
17.12.2014 / 16:39