Im with a different problem... I've googled a little but havent found anything about my problem so im asking here... I have an object JasperPrint where i generate the document... The problem is that i need to create a java.io.File from this JasperPrint without saving the file on the computer.
What do i need to do is: send a file by email. And this file must be generated by the jasperreport. I can't save the stream on the machine to delete it later... so i need to take the file in memory or something like that in runtime...
So... i have my object jasperprint and need to get a java.io.File from this one... Someone knows what do can i do?
Andrew... couldnt answer it at comment so im writing it here... In javax.mail i've done like this:
File fileAttachment = myfile;
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(fileAttachment.getName());
multipart.addBodyPart(messageBodyPart);
and its working when i pass him a file from my machine... So i think its gonna work when i use a java.io.File even if its only on memory...
You can generate the report as PDF(or other format) and send it as a file with Jasper. JRXlsExporter
some snippet:
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), jasperReports);
long start = System.currentTimeMillis();
OutputStream output = new FileOutputStream(new File("c:/output/JasperReport.pdf"));
JasperExportManager.exportReportToPdfStream(print, output);
// coding For Excel:
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JA SPER_PRINT, print);
exporterXLS.setParameter(JRXlsExporterParameter.OU TPUT_STREAM, output);
exporterXLS.setParameter(JRXlsExporterParameter.IS _ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _AUTO_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.exportReport();