We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception: Null when exporting from JasperPrint to Word

Hello everyone,


I’m having a problem exporting my JasperPrint to a simple Word document using the AWDocExporter.

Below is the code im currently using:

private static byte[] docToByteArray(JasperPrint jasperPrint, String reportLocation)
{
AWDocExporter exporter = new AWDocExporter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, reportLocation);
//Aspose Words Export parameters
exporter.setParameter(AWExporterParameter.PAGE_BREAKS, 0);
exporter.setParameter(AWExporterParameter.RECOGNIZE_FIELDS, true);
exporter.setParameter(AWExporterParameter.EXPORT_LINES, true);
exporter.setParameter(AWExporterParameter.SPACING_FACTOR, 0.1);
exporter.setParameter(AWExporterParameter.PAGE_MARGINS, “60px;60px;50px;10px”);
exporter.setParameter(AWExporterParameter.OVERLAP_RESOLUTION_METHOD, AWExporterParameter. OVERLAP_RESOLUTION_METHOD_PUSH_ITEMS);

exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
System.out.println("File Location: " + reportLocation);
exporter.exportReport(); // exports to baos
System.out.println(“Exported.”);
return baos.toByteArray();
}
catch (Exception jre)
{
System.out.println("JASPER ERROR: "+ jre.getMessage());
jre.printStackTrace();
return null;
}

Upon running this function the stacktrace simply returns “JASPER ERROR: null” and then all the subsequent calling methods. I’ve tried exporting without any of the AWExporterParameters as well as dropping the byteArrayOutputStream but it seems like the exception is thrown every time at exporter.exportReport() and I can’t figure out why.

Thanks in advance
Hi Donavan,

Thanks for your inquiry. Could you please attach following files for testing? I will investigate the issue on my side and provide you more information.

  • .jrprint file
  • jrxml files along with xml/csv data source

Hi,


Please find attached the requested documents.

Thanks for your help.

Hi Donavan,


Thanks for sharing the jrxml files. I am working over your query and will update you asap.

Hi Donavan,


Thanks for your patience. I have tested the scenario with shared jrxml/code and have not found any exception while using latest version of Aspose.Words for JasperReports 1.8.0. I have attached the output Doc file with this post for your kind reference.

Please use the latest version of Aspose.Words for JasperReports 1.8.0. hope this helps you.

Hi Tahir,


Thanks for your reply.

Can you comment on the AWExporterParameters that were used? Do they all work or should I leave some commented out? Unfortunately I have been running the latest version of Aspose.Words for JasperReports so I’m afraid that can’t be the problem.

As a failover I used the JasperReports DocxExporter - but as I’m sure you know the formatting isn’t the easiest to work with in Word.

Point is - that works, so it’s definitely not a JasperPrint or file location problem. I’m going to do some testing however on whether the file is created correctly before trying to export to it - that would potentially explain a ‘Null’ - but not really why there is no FileNotFoundException.

Thanks again for your help.

Hi Donavan,


Thanks for your inquiry. Yes, the all AWExporterParameters should work. The CSV file shared in your last post has not columns name in first row. I modified it to execute your shared jrxml. Please find the modified CSV in attachment and confirm either column names are correct or not.

It would be great if you please share your CSV with columns names.I will investigate the issue with new CSV at my side and provide you more information.