Jasper Reports exports well to PDF but not to Excel

I'm new with Jasper Reports. I'm using 5.6.0 version and I can export some data to PDF and all fields are filled correct but when I try to export the same data to Excel, some fields are missing. The code I use it's the some on both clases (I have one class for each file export)

I also read that the template to export to PDF or Excel it's the same, so I don't know why fills all in PDF and not in Excel.

When I generate the PDF I pass all the data to:

JasperExportManager.exportReportToPdfStream(jasperPrint,fileOutputStream);

And when I try to generate the Excel I call this funcion:

private void generateExcel(JasperPrint jasperPrint) throws IOException, JRException {
    JRXlsExporter exporterXLS = new JRXlsExporter();
    JFileChooser jFileChooser = new JFileChooser(".");
    jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int status = jFileChooser.showOpenDialog(SIXACOPWorkbench.getWorkbenchContext().getWorkbench().getFrame());
    if (status == JFileChooser.APPROVE_OPTION) {
        if (jFileChooser.getSelectedFile() != null) {
            String pathPDFs = (jFileChooser.getSelectedFile().getAbsolutePath());
            File ficheroXLS = new File(pathPDFs+"//testing.xls");
            FileOutputStream fos = new FileOutputStream(ficheroXLS);
            exporterXLS.setExporterInput(new SimpleExporterInput(jasperPrint));
            exporterXLS.setExporterOutput(new SimpleOutputStreamExporterOutput(fos));
            SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
            configuration.setRemoveEmptySpaceBetweenRows(true);
            configuration.setDetectCellType(true);
            configuration.setWhitePageBackground(false);
            exporterXLS.setConfiguration(configuration);
            exporterXLS.exportReport();    
            fos.close();
        }
    }
}

I think that if the template it's wrong the PDF must generate wrong but the output it's correct. And the code it's the same for both, only changes the call to the function that exports. So, what I'm doing wrong when exporting to Excel?

Regards.

ialonso's picture
65
Joined: Jan 30 2017 - 7:57am
Last seen: 6 years 5 months ago

3 Answers:

Hi,

Usually, this kind of errors are related to the report design. Overlapping elements in the report template are ignored in grid-layout-based exporters.

Unlike PDF, the Excel exporter does not support the absolute positioning of the elements. In case elements are improperly aligned, some of them might be excluded from the export (see the explanation here). To solve this, create an appropriate layout for your report, ensure there are no overlapping or misaligned elements, and then run the report again.

Regards,

Sanda

 

shertage's picture
22256
Joined: Sep 26 2006 - 8:06pm
Last seen: 2 months 3 weeks ago

Hi @shertage, thanks for the link. I'm trying to make the report template again from a new black sheet but I can't find how make reports manually.

Do you know some tutorial?

Thanks!

ialonso's picture
65
Joined: Jan 30 2017 - 7:57am
Last seen: 6 years 5 months ago

In case you are using the Jaspersoft Studio IDE, you can find several interesting tutorials and related documentation here:

http://community.jaspersoft.com/project/jaspersoft-studio/resources

Regards,

Sanda

shertage's picture
22256
Joined: Sep 26 2006 - 8:06pm
Last seen: 2 months 3 weeks ago
Feedback
randomness