henryedsl Posted December 15, 2009 Share Posted December 15, 2009 Hello friends! I am working with iReport to create JasperReports reports for my web application in java. In iReport i have created the .jasper, .jrxml and .jrprint files. In my java application i have a method to export the .jrprint file to Excel, of course, if i use the .jrprint file i created from iReport, it works fine, but i need to fill the .jrprint from my Application every time i export to excel. The problem is that it seems that the .jrprint is blank, so when i export to excel, it is a blank report. The .jrprint generated by iReport is 12 kb, but the .jrprint generated for me, it is only 2 kb. Here you can see the code i use to export to excel. public void xlsExport(String reportName) throws JRException { JasperReport report = null; JasperPrint print = null; Map parameters = new HashMap(); parameters.put("FIELD1", "AAA"); parameters.put("FIELD1", "BBB"); this.reportName = reportName; report = JasperCompileManager.compileReport(REPORT_DIRECTORY + "/" + reportName + ".jrxml"); // print = JasperFillManager.fillReport(report, parameters, AbstractDAO.getConnection()); THIS CODE DOES NOT WORK // InputStream is = null;// try {// is = new BufferedInputStream(new FileInputStream(REPORT_DIRECTORY + "/" + reportName + ".jasper"));// } catch(FileNotFoundException e) {// // } // print = JasperFillManager.fillReport(is, parameters, AbstractDAO.getConnection()); THIS CODE DOES NOT WORK addMessage(REPORT_DIRECTORY + "/" + reportName + ".jasper"); //JasperFillManager.fillReportToFile(REPORT_DIRECTORY + "/" + reportName + ".jasper", parameters, AbstractDAO.getConnection()); THIS CODE DOES NOT WORK //JasperFillManager.fillReportToFile(report, REPORT_DIRECTORY + "/" + reportName + ".jrprint", parameters, AbstractDAO.getConnection()); THIS CODE DOES NOT WORK JasperFillManager.fillReportToFile(REPORT_DIRECTORY + "/" + reportName + ".jasper", REPORT_DIRECTORY + "/" + reportName + ".jrprint", parameters, AbstractDAO.getConnection()); File file = new File(REPORT_DIRECTORY + "/" + reportName + ".jrprint"); System.out.println(REPORT_DIRECTORY + "/" + reportName + ".jrprint"); try { JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(file); JExcelApiExporter xlsExporter = new JExcelApiExporter(); xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); xlsExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,REPORT_DIRECTORY + "/" + reportName + ".xls"); System.out.println("Exporting report..."); xlsExporter.exportReport(); System.out.println("Done!"); } catch (JRException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }What's wrong with my code? What do i have to do to fill the .jrprint correctly so i can export to excel? Regards and thanks in advance for your time and help.Post Edited by henryedsl at 12/15/2009 20:16 Link to comment Share on other sites More sharing options...
henryedsl Posted December 15, 2009 Author Share Posted December 15, 2009 Hello guys, i solved the problem, my mistake. It was a problem with the connection to database. What a shame, my first post, for this :) Here s the method to export to excel, in case it is useful for someone public void xlsExport(String reportName) throws JRException { Map parameters = new HashMap(); parameters.put("FIELD1", "AAA"); parameters.put("FIELD1", "BBB"); this.reportName = reportName; JasperFillManager.fillReportToFile(REPORT_DIRECTORY + "/" + reportName + ".jasper", REPORT_DIRECTORY + "/" + reportName + ".jrprint", parameters, AbstractDAO.getConnection()); File file = new File(REPORT_DIRECTORY + "/" + reportName + ".jrprint"); System.out.println(REPORT_DIRECTORY + "/" + reportName + ".jrprint"); try { JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(file); JExcelApiExporter xlsExporter = new JExcelApiExporter(); xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); xlsExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,REPORT_DIRECTORY + "/" + reportName + ".xls"); System.out.println("Exporting report..."); xlsExporter.exportReport(); System.out.println("Done!"); } catch (JRException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } Regards... 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