Jump to content
We've recently updated our Privacy Statement, available here ×

Jasper Reports exports well to PDF but not to Excel


ialonso

Recommended Posts

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);[/code]

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();        }    }}[/code]

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.

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...