2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Neil H - neilhay How to generate XLS report? 2003-05-16 10:26 I need to create PDF and XLS report from same data, what is easiest wat to do that? also can somebody post a code to generate XLS report from DataCOllection and/or without one? I am doing following to generate PDF reports: JasperRunManager.runReportToPdfFile( reportFile.getPath(), getFileDBPath() + destfilename, parameters, getConn()); and: JasperRunManager.runReportToPdfFile( reportFile.getPath(), getFileDBPath() + destfilename, parameters, new JRBeanCollectionDataSource(divPeriodTerminalData)); By: Teodor Danciu - teodord RE: How to generate XLS report? 2003-05-17 04:19 Hi, The JasperRunManager fills the report with data and immediately exports it to PDF. But if you want to export the same documents both in PDF and XLS format, you have to give up using the JasperRunManager. Instead, you'll use the JasperFillManager that will produce an intermediate .jrprint file after filling the report template with your data (from connection or data source). And then you use the JasperExportManager or the JRPdfExporter class directly to export to the .jrprint file to PDF format. I suggest you use the exporter classes directly, because the export manager has no utility methods to export to XLS. Using the exporter classes is not difficult and you can see how the JRXlsExporter class is used in almost all the supplied samples. I hope this helps. Teodor By: Neil H - neilhay RE: How to generate XLS report? 2003-05-17 08:01 Teodor thanks for your reply. I took your suggestion. I am able to create a XLS file using exporter but problem is its blank? jprint file is around 21K.. so its not blank.DO you know why this might be happening? JasperFillManager.fillReportToFile(reportFile.getPath(), parameters, getConn()); File sourceFile = new File(getFilePath() + "XLSreport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); destfilename = "testreport.xls"; JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, getFileDBPath() + destfilename); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.exportReport(); By: rolas - rolas RE: How to generate XLS report? 2003-08-12 13:43 i have this but the answer is no output specified on the exporter: File reportFile = new File(application.getRealPath("/reports/Anexo6.jasper")); JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); Map parameters = new HashMap(); parameters.put("BaseDir", reportFile.getParentFile()); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,new HashMap(),BdConnection.getConnection()); JRXlsExporter exporter = new JRXlsExporter(); StringBuffer sbuffer = new StringBuffer(); Map imagesMap = new HashMap(); session.setAttribute("IMAGES_MAP", imagesMap); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); response.setContentType("application/vnd.ms-excel"); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.exportReport(); By: Teodor Danciu - teodord RE: How to generate XLS report? 2003-08-13 00:11 Hi, Replace this: exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); with this: exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream()); I hope this helps. Teodor Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now